├── .gitignore ├── LICENSE.md ├── README.md ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | ## ISC License 2 | 3 | Copyright (c) 2015, James Kyle 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # incremental-dom-react-helper 2 | 3 | Helper to make Google's [incremental-dom](https://github.com/google/incremental-dom) library work with React's compile target today. 4 | 5 | Example: http://jsbin.com/yoturaneca/edit?js,output 6 | 7 | ```js 8 | let dom = ( 9 |
10 |

Hello World

11 |
12 | ); 13 | 14 | IncrementalDOM.patch(document.body, dom); 15 | ``` 16 | 17 | Or rather: 18 | 19 | ```js 20 | var dom = ( 21 | React.createElement('div', { className: 'foo'}, 22 | React.createElement('h1', null, 'Hello World') 23 | ) 24 | ); 25 | 26 | IncrementalDOM.patch(document.body, dom); 27 | ``` 28 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | function parseAttrsObj(attrsObj) { 2 | var attrs = []; 3 | var keyAttr = null; 4 | 5 | var attrsObjKeys = Object.keys(attrsObj); 6 | 7 | for (var i = 0; i < attrsObjKeys.length; i++) { 8 | var key = attrsObjKeys[i]; 9 | var val = attrsObj[key]; 10 | 11 | if (key === 'key') { 12 | keyAttr = val; 13 | continue; 14 | } 15 | 16 | if (key === 'className') { 17 | key = 'class'; 18 | } 19 | 20 | attrs.push(key, val); 21 | } 22 | 23 | return { 24 | attrs: attrs, 25 | key: keyAttr 26 | } 27 | } 28 | 29 | var React = { 30 | createElement(tagName, attrs) { 31 | var children = Array.prototype.slice.call(arguments, 2); 32 | var parsedAttrs = attrs ? parseAttrsObj(attrs) : {}; 33 | 34 | return function() { 35 | IncrementalDOM.elementOpen.apply(null, [tagName, parsedAttrs.key, null].concat(parsedAttrs.attrs)); 36 | 37 | for (var i = 0; i < children.length; i++) { 38 | var child = children[i]; 39 | 40 | if (typeof child === 'string') { 41 | IncrementalDOM.text(child); 42 | } else { 43 | child(); 44 | } 45 | } 46 | 47 | IncrementalDOM.elementClose(tagName); 48 | } 49 | } 50 | }; 51 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "incremental-dom-wrapper", 3 | "version": "0.0.0", 4 | "description": "Helper to make Google's incremental-dom library work with React's compile target today.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/thejameskyle/incremental-dom-react-helper.git" 12 | }, 13 | "keywords": [ 14 | "React", 15 | "incremental-dom", 16 | "virtual-dom" 17 | ], 18 | "author": "James Kyle ", 19 | "license": "ISC", 20 | "bugs": { 21 | "url": "https://github.com/thejameskyle/incremental-dom-react-helper/issues" 22 | }, 23 | "homepage": "https://github.com/thejameskyle/incremental-dom-react-helper#readme", 24 | "dependencies": { 25 | "incremental-dom": "^0.1.0" 26 | } 27 | } 28 | --------------------------------------------------------------------------------