Permalink
Browse files

In addition to passing mutate() and mutation() as props, pass them as…

… context too!
  • Loading branch information...
developit committed Mar 11, 2016
1 parent ebf28f4 commit 0a589af00aafe947d3935a0aa1d184a3ea0040ec
Showing with 54 additions and 7 deletions.
  1. +17 −3 .eslintrc
  2. +19 −3 package.json
  3. +3 −0 rollup.config.js
  4. +9 −0 src/contextualize.js
  5. +6 −1 src/index.js
View
@@ -4,11 +4,25 @@
"env": {
"browser": true
},
"ecmaFeatures": {
"modules": true,
"jsx": true
"plugins": [
"react"
],
"settings": {
"react": {
"pragma": "h"
}
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"modules": true,
"jsx": true
}
},
"rules": {
"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2,
"no-unused-vars": [1, { "varsIgnorePattern": "^h$" }],
"no-cond-assign": 1,
"semi": 2,
View
@@ -4,17 +4,30 @@
"version": "0.2.0",
"description": "Minimal functional Virtual DOM rendering using Preact.",
"main": "dist/preact-cycle.js",
"minified:main": "dist/preact-cycle.min.js",
"jsnext:main": "src/index.js",
"scripts": {
"build": "npm run -s transpile && npm run -s minify",
"build": "npm-run-all transpile optimize minify",
"transpile": "rollup -c rollup.config.js -m ${npm_package_main}.map -f umd -n $npm_package_amdName $npm_package_jsnext_main -o $npm_package_main",
"minify": "uglifyjs $npm_package_main -bc -o $npm_package_main -p relative --in-source-map ${npm_package_main}.map --source-map ${npm_package_main}.map",
"optimize": "uglifyjs $npm_package_main -bc -o $npm_package_main -p relative --in-source-map ${npm_package_main}.map --source-map ${npm_package_main}.map",
"minify": "uglifyjs $npm_package_main -cm -o $npm_package_minified_main -p relative --in-source-map ${npm_package_main}.map --source-map ${npm_package_minified_main}.map",
"test": "eslint {src,test} && mocha --compilers js:babel-register test/**/*.js",
"prepublish": "npm run build",
"release": "npm run build && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
},
"babel": {
"presets": ["es2015-minimal", "stage-0"]
"presets": [
"es2015-minimal",
"stage-0"
],
"plugins": [
[
"transform-react-jsx",
{
"pragma": "h"
}
]
]
},
"keywords": [
"preact",
@@ -34,14 +47,17 @@
"devDependencies": {
"babel": "^6.5.1",
"babel-eslint": "^4.1.8",
"babel-plugin-transform-react-jsx": "^6.6.5",
"babel-preset-es2015": "^6.5.0",
"babel-preset-es2015-minimal": "^1.1.0",
"babel-preset-es2015-minimal-rollup": "^1.1.0",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.5.1",
"chai": "^3.5.0",
"eslint": "^1.10.3",
"eslint-plugin-react": "^4.2.1",
"mocha": "^2.4.5",
"npm-run-all": "^1.5.2",
"rollup": "^0.25.3",
"rollup-plugin-babel": "^2.3.9",
"uglify-js": "^2.6.1"
View
@@ -9,6 +9,9 @@ export default {
presets: [
'es2015-minimal-rollup',
'stage-0'
],
plugins: [
['transform-react-jsx', { pragma:'h' }]
]
})
]
View
@@ -0,0 +1,9 @@
/** High-order component that passes its props down as context. */
export default function Contextualize() {}
Contextualize.prototype.getChildContext = function() {
let { children, ...props } = this.props;
return props;
};
Contextualize.prototype.render = ({ children }) => children[0];
View
@@ -1,10 +1,15 @@
import { h, render as doRender } from 'preact';
import Contextualize from './contextualize';
import createCycle from './create-cycle';
function createRenderer(Renderable, parent) {
let root;
return props => {
root = doRender(h(Renderable, props), parent, root);
root = doRender((
<Contextualize {...props}>
<Renderable {...props} />
</Contextualize>
), parent, root);
};
}

0 comments on commit 0a589af

Please sign in to comment.