reactive-di
Advanced tools
Comparing version 4.0.2 to 4.0.3
@@ -5,2 +5,7 @@ # Change Log | ||
<a name="4.0.3"></a> | ||
## [4.0.3](https://github.com/zerkalica/reactive-di/compare/v4.0.2...v4.0.3) (2017-08-04) | ||
<a name="4.0.2"></a> | ||
@@ -7,0 +12,0 @@ ## [4.0.2](https://github.com/zerkalica/reactive-di/compare/v4.0.1...v4.0.2) (2017-08-03) |
{ | ||
"name": "reactive-di", | ||
"version": "4.0.2", | ||
"version": "4.0.3", | ||
"description": "Reactive dependency injection", | ||
@@ -22,3 +22,3 @@ "publishConfig": { | ||
"test.dev": "mocha --growl --watch", | ||
"watch": "chokidar --initial -d 2000 -t 1000 'src/**/*.js' -c 'npm run build && cp -rvf *.js src dist ../rdi-examples/node_modules/reactive-di'" | ||
"watch": "chokidar --initial -d 2000 -t 1000 'src/**/*.js' -c 'npm run build && cp -rvf *.js src dist $npm_package_config_dest/node_modules/reactive-di'" | ||
}, | ||
@@ -77,4 +77,4 @@ "author": "Stefan Zerkalica <zerkalica@gmail.com>", | ||
"dependencies": { | ||
"lom_atom": "^1.0.4" | ||
"lom_atom": "^1.0.5" | ||
} | ||
} |
129
README.md
@@ -17,27 +17,20 @@ # Reactive DI [![Build Status](https://secure.travis-ci.org/zerkalica/reactive-di.png)](http://travis-ci.org/zerkalica/reactive-di) | ||
## Architecture overview | ||
<img src="https://rawgithub.com/zerkalica/reactive-di/master/docs/workflow-state.svg" alt="reactive-di flow diagram" /> | ||
## Install | ||
``` | ||
npm install --save reactive-di | ||
npm install --save-dev babel-plugin-transform-metadata babel-plugin-inferno | ||
npm install --save reactive-di lom_atom | ||
``` | ||
For using zero-dependency components, we need to define jsx pragma in transform-metadata: | ||
Example .babelrc: | ||
.babelrc: | ||
```json | ||
{ | ||
"presets": [ | ||
"flow", | ||
"react", | ||
["es2015", {"loose": true}] | ||
], | ||
"plugins": [ | ||
["transform-metadata", { | ||
"addDisplayName": true, | ||
"jsxPragma": "_t" | ||
}], | ||
["inferno", { | ||
"pragma": "_t.h" | ||
}] | ||
"transform-decorators-legacy", | ||
["transform-react-jsx", {"pragma": "lom_h"}] | ||
] | ||
@@ -61,75 +54,53 @@ } | ||
// @flow | ||
/* eslint-env browser */ | ||
import {mem} from 'lom_atom' | ||
import {createReactWrapper, createCreateElement, Injector} from 'reactive-di' | ||
import {render, h, Component} from 'preact' | ||
import {render, createVNode as infernoCreateVNode} from 'inferno' | ||
import Component from 'inferno-component' | ||
import {createReactRdiAdapter, DiFactory, BaseSetter} from 'reactive-di' | ||
class User { | ||
name = '' | ||
} | ||
function Hello( | ||
{text}: { | ||
text: string; | ||
}, | ||
{user}: { | ||
user: User; | ||
} | ||
) { | ||
const set = new BaseSetter(user).create(BaseSetter.createEventSet) | ||
function ErrorableView({error}: {error: Error}) { | ||
return <div> | ||
<h1>Hello {user.name}</h1> | ||
<input value={user.name} onInput={set.name} /> | ||
{error instanceof mem.Wait | ||
? <div> | ||
Loading... | ||
</div> | ||
: <div> | ||
<h3>Fatal error !</h3> | ||
<div>{error.message}</div> | ||
<pre> | ||
{error.stack.toString()} | ||
</pre> | ||
</div> | ||
} | ||
</div> | ||
} | ||
// used in jsx below, jsx pragma t | ||
const _t = new DiFactory({ // eslint-disable-line | ||
createVNode: infernoCreateVNode, | ||
component: createReactRdiAdapter(Component) | ||
}) | ||
.create() | ||
render( | ||
<Hello text="test"/>, | ||
window.document.getElementById('app') | ||
const lomCreateElement = createCreateElement( | ||
createReactWrapper( | ||
Component, | ||
ErrorableView | ||
), | ||
h | ||
) | ||
``` | ||
global['lom_h'] = lomCreateElement | ||
Out: | ||
class HelloContext { | ||
@mem name = '' | ||
} | ||
```js | ||
// ... | ||
var User = function User() { | ||
_classCallCheck(this, User); | ||
this.name = ''; | ||
}; | ||
function Hello(_ref, _ref2, _t) { | ||
var text = _ref.text; | ||
var user = _ref2.user; | ||
var set = new _src.BaseSetter(user).create(_src.BaseSetter.createEventSet); | ||
return _t.h(2, 'div', null, [_t.h(2, 'h1', null, ['Hello ', user.name]), _t.h(512, 'input', { | ||
'value': user.name | ||
}, null, { | ||
'onInput': set.name | ||
})]); | ||
function HelloView( | ||
{prefix}: {prefix: string}, | ||
{context}: {context: HelloContext} | ||
) { | ||
return <div> | ||
{prefix}, {context.name} | ||
<br/><input value={context.name} onInput={ | ||
(e: Event) => { | ||
context.name = (e.target: any).value | ||
} | ||
} /> | ||
</div> | ||
} | ||
HelloView.deps = [{context: HelloContext}] | ||
Hello.displayName = 'Hello'; | ||
Hello._r2 = 1; | ||
Hello._r1 = [{ | ||
user: User | ||
}]; | ||
var _t = new _src.DiFactory({ | ||
createVNode: _inferno.createVNode, | ||
component: (0, _src.createReactRdiAdapter)(_infernoComponent2.default) | ||
}).create(); | ||
(0, _inferno.render)(_t.h(16, Hello, null, null, { text: 'test' }), window.document.getElementById('app')); | ||
render(<HelloView prefix="Hello" />, document.body) | ||
``` | ||
@@ -142,5 +113,3 @@ | ||
* [angular2](https://angular.io) ideas of hierarchical injectors. | ||
* [mobx](http://mobxjs.github.io/mobx/) ideas of unobtrusive reactive state. | ||
* [derivablejs](http://ds300.github.io/derivablejs) core engine of reactive-di | ||
* [babel-plugin-angular2-annotations](https://github.com/shuhei/babel-plugin-angular2-annotations) ideas of metadata for resolving dependencies. | ||
* [babel-plugin-type-metadata](https://github.com/stephanos/babel-plugin-type-metadata) ideas of generating metadata for flowtypes. |
// @flow | ||
import {defaultContext, mem, detached} from 'lom_atom' | ||
import {defaultContext, detached} from 'lom_atom' | ||
import type {NamesOf} from 'lom_atom' | ||
@@ -4,0 +4,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
116443
113
Updatedlom_atom@^1.0.5