Comparing version 0.1.0 to 0.2.0
@@ -48,2 +48,4 @@ 'use strict'; | ||
function createContainer(WrappedComponent, _ref) { | ||
var _ref$root = _ref.root; | ||
var root = _ref$root === undefined ? true : _ref$root; | ||
var fragments = _ref.fragments; | ||
@@ -61,4 +63,2 @@ var _ref$interactions = _ref.interactions; | ||
// eslint-disable-line | ||
function Container(props, context) { | ||
@@ -70,36 +70,42 @@ _classCallCheck(this, Container); | ||
var model = context.model; | ||
var intents = context.intents; | ||
var intentFactory = context.intentFactory; | ||
(0, _invariant2["default"])(model, 'Could not find "model" in the context\n of "' + _this.constructor.displayName + '".\n Please wrap the root component in a <Provider>'); | ||
(0, _invariant2["default"])(intents, 'Could not find "intents" in the context\n of "' + _this.constructor.displayName + '".\n Please file an issue'); | ||
(0, _invariant2["default"])(intentFactory, 'Could not find "intentFactory" in the context\n of "' + _this.constructor.displayName + '".\n Please file an issue'); | ||
// TODO consider using versions with getFragment | ||
_this.componentHasMounted = false; | ||
_this.subscription = model.$.mergeMap(function (version) { | ||
var pathsAsArrayOrObject = fragments(); | ||
var paths = undefined; | ||
if ((0, _isPlainObject2["default"])(pathsAsArrayOrObject)) { | ||
paths = (0, _toPaths.toPaths)(pathsAsArrayOrObject); | ||
} | ||
if ((0, _isPlainObject2["default"])(pathsAsArrayOrObject)) { | ||
paths = pathsAsArrayOrObject; | ||
} | ||
(0, _invariant2["default"])(paths, 'fragments of ' + _this.constructor.displayName + '\n should return paths in form of falcor pathArray syntax or use\n refar\'s object notation'); | ||
return _Observable.Observable.fromPromise(model.get.apply(model, _toConsumableArray((0, _toPaths.toPaths)(fragments())))); | ||
}).subscribe(function (data) { | ||
if (!data) { | ||
return; | ||
} | ||
if (!_this.componentHasMounted) { | ||
_this.state = data.json; | ||
return; | ||
} | ||
_this.setState(data.json); | ||
}); | ||
if (root) { | ||
_this.subscription = model.$.mergeMap(function (version) { | ||
var pathsAsArrayOrObject = fragments(); | ||
var paths = undefined; | ||
if ((0, _isPlainObject2["default"])(pathsAsArrayOrObject)) { | ||
paths = (0, _toPaths.toPaths)(pathsAsArrayOrObject); | ||
} | ||
if ((0, _isPlainObject2["default"])(pathsAsArrayOrObject)) { | ||
paths = pathsAsArrayOrObject; | ||
} | ||
(0, _invariant2["default"])(paths, 'fragments of ' + _this.constructor.displayName + '\n should return paths in form of falcor pathArray syntax or use\n refar\'s object notation'); | ||
return _Observable.Observable.fromPromise(model.get.apply(model, _toConsumableArray((0, _toPaths.toPaths)(fragments())))); | ||
}).subscribe(function (data) { | ||
if (!data) { | ||
return; | ||
} | ||
if (!_this.componentHasMounted) { | ||
_this.state = data.json; | ||
return; | ||
} | ||
_this.setState(data.json); | ||
}); | ||
} | ||
// run interactions | ||
_this.intents = interactions(model, intents); | ||
if (!Container.intents) { | ||
var intents = interactions(model, intentFactory); | ||
Container.intents = intents; | ||
} | ||
return _this; | ||
} | ||
} // eslint-disable-line | ||
_createClass(Container, [{ | ||
@@ -113,4 +119,6 @@ key: 'componentDidMount', | ||
value: function componentWillUnmount() { | ||
// Clean-up subscription before un-mounting | ||
this.subscription.unsubscribe(); | ||
if (root) { | ||
// Clean-up subscription before un-mounting | ||
this.subscription.unsubscribe(); | ||
} | ||
} | ||
@@ -120,3 +128,3 @@ }, { | ||
value: function render() { | ||
return (0, _react.createElement)(WrappedComponent, _extends({}, this.state, this.intents)); | ||
return (0, _react.createElement)(WrappedComponent, _extends({}, this.state, Container.intents, this.props)); | ||
} | ||
@@ -131,3 +139,3 @@ }]); | ||
model: _PropTypes.modelType.isRequired, | ||
intents: _react.PropTypes.object.isRequired | ||
intentFactory: _react.PropTypes.object.isRequired | ||
}; | ||
@@ -134,0 +142,0 @@ Container.fragments = fragments; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.toPaths = exports.createContainer = exports.Provider = undefined; | ||
exports.range = exports.values = exports.toPaths = exports.createContainer = exports.Provider = undefined; | ||
@@ -36,2 +36,20 @@ var _Provider = require('./Provider'); | ||
var _values = require('./utils/values'); | ||
Object.defineProperty(exports, 'values', { | ||
enumerable: true, | ||
get: function get() { | ||
return _values.values; | ||
} | ||
}); | ||
var _range = require('./utils/range'); | ||
Object.defineProperty(exports, 'range', { | ||
enumerable: true, | ||
get: function get() { | ||
return _range.range; | ||
} | ||
}); | ||
var _Observable = require('rxjs/Observable'); | ||
@@ -38,0 +56,0 @@ |
@@ -20,2 +20,6 @@ 'use strict'; | ||
var _merge = require('lodash/merge'); | ||
var _merge2 = _interopRequireDefault(_merge); | ||
var _PropTypes = require('./PropTypes'); | ||
@@ -53,5 +57,5 @@ | ||
var model = this.model; | ||
var intents = this.intents; | ||
var intentFactory = this.intentFactory; | ||
return { model: model, intents: intents }; | ||
return { model: model, intentFactory: intentFactory }; | ||
} | ||
@@ -69,6 +73,10 @@ }]); | ||
// usefull for haveing local changes | ||
_this.model.setLocal = function (obj) { | ||
_this.model.assign = function (obj) { | ||
_this.model.setCache(Object.assign(_this.model.getCache(), obj)); | ||
}; | ||
_this.model.deepAssign = function (obj) { | ||
_this.model.setCache((0, _merge2["default"])(_this.model.getCache(), obj)); | ||
}; | ||
// changes to model should be broadcasted | ||
@@ -86,9 +94,9 @@ // TODO do I need getVersion? | ||
// create intents | ||
_this.intents = {}; | ||
_this.intents.get = function (name) { | ||
_this.intentFactory = {}; | ||
_this.intentFactory.get = function (name) { | ||
(0, _invariant2["default"])(name, 'Invalid name for the intent collection.'); | ||
if (!_this.intents[name]) { | ||
_this.intents[name] = new _Subject.Subject(); | ||
if (!_this.intentFactory[name]) { | ||
_this.intentFactory[name] = new _Subject.Subject(); | ||
} | ||
return _this.intents[name]; | ||
return _this.intentFactory[name]; | ||
}; | ||
@@ -116,3 +124,3 @@ return _this; | ||
model: _PropTypes.modelType.isRequired, | ||
intents: _react.PropTypes.object.isRequired | ||
intentFactory: _react.PropTypes.object.isRequired | ||
}; | ||
@@ -119,0 +127,0 @@ |
{ | ||
"name": "refar", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Falcor + Rx + React connector library", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -13,3 +13,3 @@ import { Component, PropTypes, createElement } from 'react' | ||
export function createContainer(WrappedComponent, { fragments, interactions = defaultInteractions }) { | ||
export function createContainer(WrappedComponent, { root = true, fragments, interactions = defaultInteractions }) { | ||
invariant(fragments, `There is no point of using createContainer | ||
@@ -28,8 +28,9 @@ for ${WrappedComponent.displayName || WrappedComponent.name} | ||
model: modelType.isRequired, | ||
intents: PropTypes.object.isRequired | ||
intentFactory: PropTypes.object.isRequired | ||
} | ||
static fragments = fragments // eslint-disable-line | ||
static intents | ||
constructor(props, context) { | ||
super(props, context) | ||
const { model, intents } = context | ||
const { model, intentFactory } = context | ||
invariant(model, | ||
@@ -40,4 +41,4 @@ `Could not find "model" in the context | ||
) | ||
invariant(intents, | ||
`Could not find "intents" in the context | ||
invariant(intentFactory, | ||
`Could not find "intentFactory" in the context | ||
of "${this.constructor.displayName}". | ||
@@ -49,3 +50,4 @@ Please file an issue` | ||
this.subscription = model.$. | ||
if (root) { | ||
this.subscription = model.$. | ||
mergeMap(version => { | ||
@@ -78,5 +80,9 @@ const pathsAsArrayOrObject = fragments() | ||
}) | ||
} | ||
// run interactions | ||
this.intents = interactions(model, intents) | ||
if (!Container.intents) { | ||
const intents = interactions(model, intentFactory) | ||
Container.intents = intents | ||
} | ||
} | ||
@@ -87,7 +93,9 @@ componentDidMount() { | ||
componentWillUnmount() { | ||
// Clean-up subscription before un-mounting | ||
this.subscription.unsubscribe() | ||
if (root) { | ||
// Clean-up subscription before un-mounting | ||
this.subscription.unsubscribe() | ||
} | ||
} | ||
render() { | ||
return createElement(WrappedComponent, { ...this.state, ...this.intents }) | ||
return createElement(WrappedComponent, { ...this.state, ...Container.intents, ...this.props }) | ||
} | ||
@@ -94,0 +102,0 @@ } |
@@ -9,1 +9,3 @@ /* eslint-disable no-unused-vars */ | ||
export { toPaths } from './utils/toPaths' | ||
export { values } from './utils/values' | ||
export { range } from './utils/range' |
@@ -5,2 +5,3 @@ import { Component, PropTypes, Children } from 'react' | ||
import invariant from 'invariant' | ||
import merge from 'lodash/merge' | ||
@@ -32,7 +33,7 @@ import { modelType } from './PropTypes' | ||
model: modelType.isRequired, | ||
intents: PropTypes.object.isRequired | ||
intentFactory: PropTypes.object.isRequired | ||
} | ||
getChildContext() { // eslint-disable-line | ||
const { model, intents } = this | ||
return { model, intents } | ||
const { model, intentFactory } = this | ||
return { model, intentFactory } | ||
} | ||
@@ -45,6 +46,10 @@ constructor(props, context) { | ||
// usefull for haveing local changes | ||
this.model.setLocal = obj => { | ||
this.model.assign = obj => { | ||
this.model.setCache(Object.assign(this.model.getCache(), obj)) | ||
} | ||
this.model.deepAssign = obj => { | ||
this.model.setCache(merge(this.model.getCache(), obj)) | ||
} | ||
// changes to model should be broadcasted | ||
@@ -62,9 +67,9 @@ // TODO do I need getVersion? | ||
// create intents | ||
this.intents = {} | ||
this.intents.get = name => { | ||
this.intentFactory = {} | ||
this.intentFactory.get = name => { | ||
invariant(name, 'Invalid name for the intent collection.') | ||
if (!this.intents[name]) { | ||
this.intents[name] = new Subject() | ||
if (!this.intentFactory[name]) { | ||
this.intentFactory[name] = new Subject() | ||
} | ||
return this.intents[name] | ||
return this.intentFactory[name] | ||
} | ||
@@ -71,0 +76,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
468593
19
10780
1
15
18