Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rayd committed Aug 29, 2016
1 parent a663414 commit 7788cfd
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

Library for turning strings and DOM nodes into virtual DOM nodes compatible with [Snabbdom](https://github.com/paldepind/snabbdom).

### Usage
## API

### `virtualize(nodes, options)`
* `nodes: Element|String` - Either a DOM `Element` or a string of HTML to turn into a set of virtual DOM nodes.
* `options: Object` - A hash of options to pass into the virtualize call. Available options are currently:
* `context: Document` - An alternative DOM document to use (default is `window.document`).
* `hooks: Object` - An object specifying hooks to call during the virtualization process. See the [hooks](#hooks) section below.

## Usage

Add it to your application with

Expand Down Expand Up @@ -34,7 +42,19 @@ let vnode = virtualize(topNode);


// String
let vnode = virtualize('<div>Click <a href="http://example.com">here</a>');
let vnode = virtualize('<div>Click <a href="http://example.com">here</a></div>');
```

#### Specifying a different document

You can specify a different DOM document (other than the default `window.document` in a browser) by passing a `context` option into your calls to `virtualize`. This will allow for usage in a server-side setting, where there is no browser. One option is to use `jsdom` to create a DOM document that can be used:

```javascript
const virtualize = require('snabbdom-virtualize').default;
const jsdom = require('jsdom').jsdom;
virtualizeString('<div>Click <a href="http://example.com">here</a></div>', {
context: jsdom('<html></html>')
});
```

#### Using modules à la carte
Expand All @@ -61,7 +81,7 @@ let vnode = virtualize(topNode);
// HTML strings.
import virtualize from 'snabbdom-virtualize/strings';

let vnode = virtualize('<div>Click <a href="http://example.com">here</a>');
let vnode = virtualize('<div>Click <a href="http://example.com">here</a></div>');

```

Expand Down

0 comments on commit 7788cfd

Please sign in to comment.