From 3ebc229bbb9beee67bc10ac1b3adcb56ab0e6a47 Mon Sep 17 00:00:00 2001 From: TylorS Date: Wed, 9 Dec 2015 06:04:44 -0500 Subject: [PATCH 1/2] docs(README): add useful information Add Travis-CI badge Show how it can be installed via npm Information on libraries which are used and exported. Highlight the key differences between Motorcycle-DOM and Cycle-DOM Add a basic usage example to show how it's imported and expected to be used in a Motorcycle application. Add information on API with links to exported variables respective documentation. Closes #15 --- README.md | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 291c1ba..889cd2b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,104 @@ -# Motorcycle.js DOM Driver +# Motorcycle.js DOM Driver [![Build Status](https://travis-ci.org/motorcyclejs/dom.svg?branch=develop)](https://travis-ci.org/motorcyclejs/dom) -The Standard DOM Driver for motorcycle.js +The Standard DOM Driver for Motorcycle. Built using [Snabbdom](https://github.com/paldepind/snabbdom) for it's modularity and it's faster *virtual-dom* implementation. This library exports the fantastic [hyperscript-helpers](https://github.com/ohanhi/hyperscript-helpers) library for ease-of-use. -More information available soon! +## Installing +``` +$ npm install @motorcycle/dom +``` + +## Want to Contribute? + +If you found an issue or want to contribute code, please read +the [contributing guidelines](https://github.com/motorcyclejs/motorcycle/blob/master/CONTRIBUTING.md). + +## Differences from [Cycle-DOM](https://github.com/cyclejs/cycle-dom) + +Many of the differences come from Snabbdom itself, and I highly recommend +reading through their +[documentation](https://github.com/paldepind/snabbdom#introduction) +first to discover the differences between Matt Esch's *Virtual-DOM*. + +A less obvious difference is how this driver patches the DOM. + +For Example - Given the view `h1('Hello, World!')` being patched to `
` this is how it will look after being patched. +```html + +
+

Hello, World!

+
+ + +

Hello, World

+``` +This library does **not** keep the root element it is patched to for +performance reasons. + +## Examples +Basic usage + +```js + +import most from 'most' +import {run} from '@motorcycle/core' +import {makeDOMDriver, h} from '@motorcycle/dom' + +function main(sources) { + ... + return { + DOM: view$, + } +} + +run(main, { + DOM: makeDOMDriver('#app') +}) +``` + +More examples can be found [here](https://github.com/motorcyclejs/examples). + +## API + +### makeDOMDriver(container, modules) + +###### Arguments + +**container** :: Element|CSS-Selector - A DOM node or a CSS-Selector which points to an existing DOM node that will be used as the initial place to patch the DOM. + +**modules** :: Array - An array of [Snabbdom modules](https://github.com/paldepind/snabbdom#creating-modules) which will be used by Snabbdom to add/remove behaviors that are available to you from the `h()` or `hyperscript-helpers` functions. + +```js +import {makeDOMDriver} from '@motorcycle/dom' + +makeDOMDriver('#app') +// or +makeDOMDriver(document.querySelector('#app')) + +/* with modules */ +/* these are the default modules used */ +makeDOMDriver('#app', [ + require(`snabbdom/modules/class`), + require(`snabbdom/modules/props`), + require(`snabbdom/modules/attributes`), + require(`snabbdom/modules/style`), +]) +``` + +### h(selector, data, children) + +###### Importing +```js +import {h} from '@motorcycle/dom' +``` + +For more information on how to use `h()` please refer to the original documentation - https://github.com/paldepind/snabbdom#snabbdomh + +### hyperscript-helpers + +###### Importing +```js +import {div, h1, p} from '@motorcycle/dom' +``` + +For more information on how to use hyperscript-helpers - +https://github.com/ohanhi/hyperscript-helpers#how-to-use From c0805c17536ab0fca7c0a1e97c255d800536b77f Mon Sep 17 00:00:00 2001 From: TylorS Date: Wed, 9 Dec 2015 09:05:57 -0500 Subject: [PATCH 2/2] docs(README): various fixes Proper usage of English. Thanks @Frikki Removes unnecessary lines Closes #15 --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 889cd2b..d963f8e 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ first to discover the differences between Matt Esch's *Virtual-DOM*. A less obvious difference is how this driver patches the DOM. -For Example - Given the view `h1('Hello, World!')` being patched to `
` this is how it will look after being patched. +For Example, Given the view `h1('Hello, World!')` being patched to `
`, this is how it will look after being patched: ```html
@@ -91,7 +91,7 @@ makeDOMDriver('#app', [ import {h} from '@motorcycle/dom' ``` -For more information on how to use `h()` please refer to the original documentation - https://github.com/paldepind/snabbdom#snabbdomh +For more information on how to use `h()`, please refer to the [original documentation](https://github.com/paldepind/snabbdom#snabbdomh). ### hyperscript-helpers @@ -100,5 +100,4 @@ For more information on how to use `h()` please refer to the original documentat import {div, h1, p} from '@motorcycle/dom' ``` -For more information on how to use hyperscript-helpers - -https://github.com/ohanhi/hyperscript-helpers#how-to-use +For more information on [how to use hyperscript-helpers](https://github.com/ohanhi/hyperscript-helpers#how-to-use).