reactive-di
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -27,3 +27,4 @@ 'use strict'; | ||
WrappedComponent.prototype.componentWillMount = function componentWillMount() { | ||
this._consumer = this.constructor.__factory.create(this, this.props); | ||
this._consumer = this.constructor.__factory.create(this); | ||
this._consumer.willMount(this.props); | ||
}; | ||
@@ -30,0 +31,0 @@ |
@@ -29,3 +29,3 @@ 'use strict'; | ||
if (args.length) { | ||
target._rdiArgs = args; | ||
target._rdiArg = args; | ||
} | ||
@@ -58,2 +58,3 @@ return target; | ||
target._rdiKey = rec.key; | ||
target._rdiConstr = rec.construct || false; | ||
target._rdiInst = rec.instance || false; | ||
@@ -60,0 +61,0 @@ target._rdiLoaded = rec.loaded || false; |
@@ -62,3 +62,3 @@ 'use strict'; | ||
this._errorComponent = meta.errorComponent ? context.resolveConsumer(meta.errorComponent).create(fakeUpdater, {}) : null; | ||
this._errorComponent = meta.errorComponent ? context.resolveConsumer(meta.errorComponent).create(fakeUpdater) : null; | ||
@@ -96,3 +96,3 @@ this._args = meta.args ? context.resolveDeps(meta.args) : null; | ||
} catch (e) { | ||
this.context.errorHandler.setError(e); | ||
this.context.notifier.onError(e, this.displayName); | ||
} | ||
@@ -99,0 +99,0 @@ }; |
@@ -26,8 +26,4 @@ 'use strict'; | ||
ConsumerFactory.prototype.create = function create(updater, props) { | ||
var listener = this._cached ? this._cached.create(updater) : new _Consumer2.default(this._meta, this.context.copy(this.displayName).register(this._meta.register)).create(updater); | ||
listener.willMount(props); | ||
return listener; | ||
ConsumerFactory.prototype.create = function create(updater) { | ||
return this._cached ? this._cached.create(updater) : new _Consumer2.default(this._meta, this.context.copy(this.displayName).register(this._meta.register)).create(updater); | ||
}; | ||
@@ -34,0 +30,0 @@ |
@@ -24,3 +24,3 @@ 'use strict'; | ||
this._lastError = null; | ||
this._props = null; | ||
this.props = null; | ||
this._lastProps = null; | ||
@@ -36,3 +36,3 @@ this._hook = hook; | ||
this._lastError = e; | ||
this._context.errorHandler.setError(e); | ||
this._context.notifier.onError(e, this.displayName); | ||
}; | ||
@@ -45,5 +45,5 @@ | ||
} | ||
var hook = this._hook; | ||
try { | ||
this._hook.willUpdate(props, oldProps); | ||
(hook.cached || hook.get()).willUpdate(props, oldProps); | ||
} catch (e) { | ||
@@ -56,6 +56,8 @@ this._setError(e); | ||
this._lastProps = null; | ||
this._lastState = null; | ||
this._props = Object.assign({}, this._props, { item: newItem }); | ||
this._context.notifier.notify([this], this, this._props); | ||
this._updater.setProps(this._props); | ||
// this._lastState = null | ||
var newProps = Object.assign({}, this.props, { item: newItem }); | ||
if (this.shouldUpdate(newProps)) { | ||
this._context.notifier.notify([this], this.displayName, this.props, newProps); | ||
this._updater.setProps(this.props); | ||
} | ||
}; | ||
@@ -77,10 +79,12 @@ | ||
} | ||
var hasReceiveProps = !!(this._hook.cached || this._hook.get()).willUpdate; | ||
if (!oldProps && props || !props && oldProps) { | ||
this._props = props; | ||
this.props = props; | ||
if (hasReceiveProps) { | ||
this._willUpdate(props, oldProps); | ||
} | ||
return true; | ||
} | ||
var hasReceiveProps = !!(this._hook.cached || this._hook.get()).willUpdate; | ||
var lpKeys = 0; | ||
@@ -93,3 +97,3 @@ for (var k in oldProps) { | ||
} | ||
this._props = props; | ||
this.props = props; | ||
return true; | ||
@@ -107,3 +111,3 @@ } | ||
} | ||
this._props = props; | ||
this.props = props; | ||
return true; | ||
@@ -119,3 +123,3 @@ } | ||
if (hook.didMount) { | ||
hook.didMount(this._props); | ||
hook.didMount(this.props); | ||
} | ||
@@ -131,3 +135,3 @@ } catch (e) { | ||
if (hook.didUpdate) { | ||
hook.didUpdate(this._props); | ||
hook.didUpdate(this.props); | ||
} | ||
@@ -145,5 +149,6 @@ } catch (e) { | ||
console.error('Can\'t render error: error component is not defined'); // eslint-disable-line | ||
throw error; | ||
// throw error | ||
return null; | ||
} | ||
errorComponent.shouldUpdate({ error: error }); | ||
errorComponent.props = { error: error }; | ||
return errorComponent.render(); | ||
@@ -188,3 +193,3 @@ }; | ||
} | ||
this._lastProps = this._props; | ||
this._lastProps = this.props; | ||
this._lastState = this._parent.state; | ||
@@ -195,3 +200,3 @@ try { | ||
notifier.trace = this._trace; | ||
var result = (this._proto.cached || this._proto.get())(this._props, this._lastState, this); | ||
var result = (this._proto.cached || this._proto.get())(this.props, this._lastState, this); | ||
notifier.trace = oldTrace; | ||
@@ -210,7 +215,10 @@ return result; | ||
if (hook.willUnmount) { | ||
hook.willUnmount(this._props); | ||
hook.willUnmount(this.props); | ||
} | ||
var prop = this._props.item; | ||
if (prop && prop[_IndexCollection.itemKey]) { | ||
prop[_IndexCollection.itemKey].listener = _IndexCollection.fakeListener; | ||
var prop = this.props.item; | ||
if (prop) { | ||
var p = prop[_IndexCollection.itemKey]; | ||
if (p && p.listener === this) { | ||
p.listener = _IndexCollection.fakeListener; | ||
} | ||
} | ||
@@ -223,3 +231,3 @@ } catch (e) { | ||
ConsumerListener.prototype.willMount = function willMount(props) { | ||
this._props = props; | ||
this.props = props; | ||
var prop = props.item; | ||
@@ -233,3 +241,3 @@ if (prop && prop[_IndexCollection.itemKey]) { | ||
if (hook.willMount) { | ||
hook.willMount(this._props); | ||
hook.willMount(this.props); | ||
} | ||
@@ -236,0 +244,0 @@ } catch (e) { |
@@ -53,3 +53,3 @@ 'use strict'; | ||
key: key, | ||
args: key._rdiArgs || null, | ||
args: key._rdiArg || null, | ||
hook: key._rdiHook || null, | ||
@@ -70,3 +70,3 @@ errorComponent: componentMeta.onError || key === this._defaultErrorComponent ? null : this._defaultErrorComponent, | ||
func: key._rdiFn || false, | ||
args: key._rdiArgs || null, | ||
args: key._rdiArg || null, | ||
ender: key._rdiEnd || isHook || false, | ||
@@ -79,2 +79,3 @@ hook: key._rdiHook || null | ||
var instance = !!key._rdiInst; | ||
var construct = !!key._rdiConstr; | ||
var name = key._rdiKey || (0, _debugName2.default)(key); | ||
@@ -84,3 +85,4 @@ var configValue = this._values[name] || null; | ||
if (configValue) { | ||
initialValue = instance ? configValue : Object.assign(new key(), configValue); // eslint-disable-line | ||
initialValue = instance ? configValue : construct ? new key(configValue) // eslint-disable-line | ||
: Object.assign(new key(), configValue); // eslint-disable-line | ||
} else { | ||
@@ -87,0 +89,0 @@ initialValue = new key(); // eslint-disable-line |
@@ -8,3 +8,4 @@ 'use strict'; | ||
// eslint-disable-line | ||
var setterKey = exports.setterKey = Symbol('rdi:setter'); | ||
//# sourceMappingURL=interfaces.js.map |
@@ -37,4 +37,5 @@ 'use strict'; | ||
this.cached = meta.initialValue; | ||
this._hook = this.context.resolveHook(meta.hook); | ||
this._meta = meta; | ||
this.isResolving = !!meta.hook; | ||
this._hook = !meta.hook ? context.resolveHook(null) : null; | ||
this._isFetching = meta.isFetching; | ||
@@ -44,6 +45,8 @@ this._isPending = meta.isPending; | ||
Source.prototype.willMount = function willMount(_parent) { | ||
Source.prototype.willMount = function willMount(parent) { | ||
if (this._parent) { | ||
if (!this._parent.refs) { | ||
this._parent.willMount(parent); | ||
} | ||
this._parent.refs++; | ||
this._parent.willMount(_parent); | ||
} | ||
@@ -77,2 +80,10 @@ var hook = this._hook.cached || this._hook.get(); | ||
Source.prototype.resolve = function resolve() { | ||
if (this.isResolving) { | ||
this.isResolving = false; | ||
if (!this._hook) { | ||
this._hook = this.context.resolveHook(this._meta.hook); | ||
} | ||
// return | ||
} | ||
var _context$binder = this.context.binder, | ||
@@ -90,5 +101,5 @@ stack = _context$binder.stack, | ||
if (!rec.has[source.id]) { | ||
rec.has[source.id] = true; | ||
if (rec.v.t === 3) { | ||
// status | ||
rec.has[source.id] = true; | ||
if (isFetching) { | ||
@@ -102,2 +113,3 @@ source = this.status || this.getStatus(); | ||
} else if (i >= level || source !== this) { | ||
rec.has[source.id] = true; | ||
// consumer or computed | ||
@@ -163,3 +175,3 @@ if (rec.v.t === 2) { | ||
} | ||
context.notifier.notify(this.consumers.items, this, v); | ||
context.notifier.notify(this.consumers.items, this.displayName, this.cached, v); | ||
this.cached = v; | ||
@@ -166,0 +178,0 @@ }; |
@@ -8,3 +8,3 @@ 'use strict'; | ||
var Transact = function () { | ||
function Transact(middlewares) { | ||
function Transact() { | ||
_classCallCheck(this, Transact); | ||
@@ -17,17 +17,30 @@ | ||
this.lastId = 0; | ||
this._middlewares = middlewares; | ||
} | ||
Transact.prototype.notify = function notify(consumers, info, value) { | ||
Transact.prototype.notify = function notify(consumers, modelName, oldValue, newValue) { | ||
var ac = this._consumers; | ||
this._consumers = ac.length ? ac.concat(consumers) : consumers; | ||
if (this._middlewares) { | ||
this._middlewares.onSetValue(info, value, this); | ||
if (this.logger) { | ||
this.logger.get().onSetValue({ | ||
trace: this.trace, | ||
callerId: this.callerId, | ||
asyncType: this.asyncType, | ||
modelName: modelName, | ||
oldValue: oldValue, | ||
newValue: newValue | ||
}); | ||
} | ||
}; | ||
Transact.prototype.onError = function onError(e, name) { | ||
if (this.logger) { | ||
this.logger.get().onError(e, name); | ||
} | ||
}; | ||
Transact.prototype.end = function end() { | ||
if (!this.trace) { | ||
var consumers = this._consumers; | ||
// consumer.pull can recursively run Transact.end, protect from this | ||
this._consumers = []; | ||
for (var i = 0, l = consumers.length; i < l; i++) { | ||
@@ -39,3 +52,2 @@ var consumer = consumers[i]; | ||
} | ||
this._consumers = []; | ||
} | ||
@@ -42,0 +54,0 @@ }; |
@@ -28,3 +28,2 @@ 'use strict'; | ||
this.componentFactory = c.componentFactory; | ||
this.errorHandler = c.errorHandler; | ||
this.protoFactory = c.protoFactory; | ||
@@ -148,2 +147,9 @@ this.binder = c.binder; | ||
Di.prototype.resolveComputed = function resolveComputed(key) { | ||
var rec = this._depFactory.computed(key, this); | ||
rec.resolve(); | ||
return rec; | ||
}; | ||
Di.prototype.resolveHook = function resolveHook(key) { | ||
@@ -150,0 +156,0 @@ if (!key) { |
@@ -30,14 +30,2 @@ 'use strict'; | ||
var DefaultErrorHandler = function () { | ||
function DefaultErrorHandler() { | ||
_classCallCheck(this, DefaultErrorHandler); | ||
} | ||
DefaultErrorHandler.prototype.setError = function setError(e) { | ||
console.error(e); // eslint-disable-line | ||
}; | ||
return DefaultErrorHandler; | ||
}(); | ||
var DiFactory = function () { | ||
@@ -49,8 +37,8 @@ function DiFactory(opts) { | ||
values.AbstractSheetFactory = opts.themeFactory; | ||
this._loggerKey = opts.logger || null; | ||
var context = this._staticContext = { | ||
depFactory: new _DepFactory2.default(values, opts.defaultErrorComponent), | ||
notifier: new _Transact2.default(opts.middlewares || null), | ||
notifier: new _Transact2.default(), | ||
componentFactory: opts.componentFactory, | ||
binder: new _RelationBinder2.default(), | ||
errorHandler: opts.errorHandler || new DefaultErrorHandler(), | ||
protoFactory: null, | ||
@@ -65,3 +53,8 @@ contexts: opts.debug ? new _DisposableCollection2.default() : null | ||
DiFactory.prototype.create = function create() { | ||
return new _Di2.default('root', [], this._staticContext, []); | ||
var di = new _Di2.default('root', [], this._staticContext, []); | ||
if (this._loggerKey) { | ||
this._staticContext.notifier.logger = di.resolveComputed(this._loggerKey); | ||
} | ||
return di; | ||
}; | ||
@@ -68,0 +61,0 @@ |
'use strict'; | ||
exports.__esModule = true; | ||
exports.AbstractSheetFactory = exports.DiFactory = exports.IndexCollection = exports.RecoverableError = exports.Updater = exports.BaseModel = exports.refsSetter = exports.eventSetter = exports.setter = exports.debugName = exports.SourceStatus = exports.ReactComponentFactory = undefined; | ||
exports.AbstractSheetFactory = exports.DiFactory = exports.IndexCollection = exports.RecoverableError = exports.Updater = exports.BaseModel = exports.refsSetter = exports.eventSetter = exports.setterKey = exports.setter = exports.debugName = exports.SourceStatus = exports.ReactComponentFactory = undefined; | ||
@@ -41,2 +41,4 @@ var _interfaces = require('./theme/interfaces'); | ||
var _interfaces2 = require('./atoms/interfaces'); | ||
var _SourceStatus = require('./atoms/SourceStatus'); | ||
@@ -56,2 +58,3 @@ | ||
exports.setter = _wrapObject.setter; | ||
exports.setterKey = _interfaces2.setterKey; | ||
exports.eventSetter = _wrapObject.eventSetter; | ||
@@ -58,0 +61,0 @@ exports.refsSetter = _refsSetter2.default; |
@@ -39,4 +39,4 @@ 'use strict'; | ||
return GenericThemeHook; | ||
}(), _class._rdiArgs = [_interfaces.AbstractSheetFactory], _temp); | ||
}(), _class._rdiArg = [_interfaces.AbstractSheetFactory], _temp); | ||
exports.default = GenericThemeHook; | ||
//# sourceMappingURL=GenericThemeHook.js.map |
@@ -24,2 +24,8 @@ 'use strict'; | ||
BaseModel.prototype.commit = function commit() { | ||
this[_interfaces.setterKey].set(this); | ||
return this; | ||
}; | ||
BaseModel.prototype.reset = function reset() { | ||
@@ -26,0 +32,0 @@ var val = new this.constructor();this[_interfaces.setterKey].set(val); |
@@ -60,3 +60,3 @@ 'use strict'; | ||
IdIndexer.prototype.get = function get(ids) { | ||
IdIndexer.prototype.pick = function pick(ids) { | ||
var map = this._map; | ||
@@ -63,0 +63,0 @@ var result = []; |
@@ -25,2 +25,3 @@ 'use strict'; | ||
var IndexCollection = function () { | ||
// @@iterator(): Iterator<Item>; | ||
function IndexCollection(recs, newItems, indexer) { | ||
@@ -32,13 +33,11 @@ _classCallCheck(this, IndexCollection); | ||
var Idxr = this.constructor.Indexer; | ||
this.indexer = indexer || (Idxr ? new Idxr() : new _IdIndexer2.default()); | ||
this._indexer = indexer || (Idxr ? new Idxr() : new _IdIndexer2.default()); | ||
} | ||
// @@iterator(): Iterator<Item>; | ||
IndexCollection.prototype.copy = function copy(items) { | ||
return new this.constructor(items, null, this.indexer); | ||
return new this.constructor(items, null, this._indexer); | ||
}; | ||
IndexCollection.prototype._copy = function _copy(items) { | ||
var newObj = new this.constructor(null, items, this.indexer); | ||
var newObj = new this.constructor(null, items, this._indexer); | ||
var source = newObj[_interfaces.setterKey] = this[_interfaces.setterKey]; | ||
@@ -50,2 +49,6 @@ | ||
IndexCollection.prototype._notify = function _notify(items) { | ||
return this.constructor.autoNotify ? this._copy(items || this._items) : this; | ||
}; | ||
IndexCollection.prototype._recsToItems = function _recsToItems(recs) { | ||
@@ -71,4 +74,4 @@ var protoItem = new this.constructor.Item(); | ||
IndexCollection.prototype.removeAll = function removeAll() { | ||
if (this.indexer) { | ||
this.indexer.removeAll(); | ||
if (this._indexer) { | ||
this._indexer.removeAll(); | ||
} | ||
@@ -82,2 +85,10 @@ return this._copy([]); | ||
IndexCollection.prototype.pick = function pick(ids) { | ||
if (!this._indexer) { | ||
throw new Error('Indexer not implemented'); | ||
} | ||
return this._indexer.pick(ids); | ||
}; | ||
IndexCollection.prototype.remove = function remove(ptr, count) { | ||
@@ -88,6 +99,4 @@ var index = ptr[itemKey].i; | ||
items.splice(index, cnt); | ||
if (this.indexer) { | ||
var indexer = this.indexer; | ||
if (this._indexer) { | ||
var indexer = this._indexer; | ||
for (var i = index, l = index + cnt; i < l; i++) { | ||
@@ -101,13 +110,13 @@ indexer.remove(items[i], i); | ||
} | ||
return this._copy(this._items); | ||
items.splice(index, cnt); | ||
return this._copy(items); | ||
}; | ||
IndexCollection.prototype.insertMultiple = function insertMultiple(ptr, newItems) { | ||
var _items; | ||
var index = ptr[itemKey].i; | ||
(_items = this._items).splice.apply(_items, [index, 0].concat(newItems)); | ||
var items = this._items; | ||
items.splice.apply(items, [index, 0].concat(newItems)); | ||
var cnt = index; | ||
var indexer = this.indexer; | ||
var indexer = this._indexer; | ||
var nl = indexer ? index + newItems.length : 0; | ||
@@ -121,3 +130,3 @@ for (var i = index, l = items.length; i < l; i++) { | ||
} | ||
return this._copy(this._items); | ||
return this._copy(items); | ||
}; | ||
@@ -129,8 +138,9 @@ | ||
IndexCollection.prototype.set = function set(ptr, newItem) { | ||
IndexCollection.prototype.set = function set(ptr, ni) { | ||
var index = ptr[itemKey].i; | ||
var newItem = ni || ptr; | ||
var item = this._items[index]; | ||
if (item !== newItem) { | ||
if (this.indexer) { | ||
this.indexer.update(newItem, item, index); | ||
if (this._indexer) { | ||
this._indexer.update(newItem, item, index); | ||
} | ||
@@ -141,3 +151,4 @@ this._items[index] = newItem; | ||
} | ||
return this; | ||
return this._notify(); | ||
}; | ||
@@ -158,4 +169,4 @@ | ||
if (oldItem !== newItem || !updateFn) { | ||
if (this.indexer) { | ||
this.indexer.update(newItem, oldItem, index); | ||
if (this._indexer) { | ||
this._indexer.update(newItem, oldItem, index); | ||
} | ||
@@ -166,3 +177,4 @@ this._items[index] = newItem; | ||
} | ||
return this; | ||
return this._notify(); | ||
}; | ||
@@ -172,3 +184,3 @@ | ||
var items = this._items; | ||
var indexer = this.indexer; | ||
var indexer = this._indexer; | ||
for (var i = 0, l = items.length; i < l; i++) { | ||
@@ -187,3 +199,3 @@ var _item3 = items[i]; | ||
return this; | ||
return this._notify(); | ||
}; | ||
@@ -193,3 +205,3 @@ | ||
var items = this._items; | ||
var indexer = this.indexer; | ||
var indexer = this._indexer; | ||
for (var i = 0, l = items.length; i < l; i++) { | ||
@@ -210,3 +222,3 @@ var _item4 = items[i]; | ||
return this; | ||
return this._notify(); | ||
}; | ||
@@ -219,4 +231,4 @@ | ||
}; | ||
if (this.indexer) { | ||
this.indexer.add(item, i); | ||
if (this._indexer) { | ||
this._indexer.add(item, i); | ||
} | ||
@@ -230,4 +242,4 @@ | ||
var item = this._items.pop(); | ||
if (this.indexer) { | ||
this.indexer.remove(item, this._items.length); | ||
if (this._indexer) { | ||
this._indexer.remove(item, this._items.length); | ||
} | ||
@@ -246,7 +258,26 @@ return this._copy(this._items); | ||
IndexCollection.prototype.filter = function filter(filterFn) { | ||
return this._items.filter(filterFn); | ||
var indexer = this._indexer; | ||
var items = this._items; | ||
var newItems = []; | ||
for (var i = 0, j = 0, l = items.length; i < l; i++) { | ||
var _item5 = items[i]; | ||
_item5[itemKey].i = j; | ||
if (filterFn(_item5, i)) { | ||
newItems.push(_item5); | ||
j++; | ||
} else { | ||
indexer.remove(_item5, i); | ||
} | ||
} | ||
return this._copy(newItems); | ||
}; | ||
IndexCollection.prototype.sort = function sort(sortFn) { | ||
return this._items.sort(sortFn); | ||
var sorted = this._items.sort(sortFn); | ||
for (var i = 0, l = sorted.length; i < l; i++) { | ||
sorted[i][itemKey].i = i; | ||
} | ||
return this._copy(sorted); | ||
}; | ||
@@ -253,0 +284,0 @@ |
@@ -31,2 +31,10 @@ 'use strict'; | ||
_this.retry = function () { | ||
_this._controllable.run(); | ||
}; | ||
_this.abort = function () { | ||
_this._controllable.abort(); | ||
}; | ||
_this.stack = orig.stack; | ||
@@ -38,10 +46,2 @@ _this.orig = orig; | ||
RecoverableError.prototype.retry = function retry() { | ||
this._controllable.run(); | ||
}; | ||
RecoverableError.prototype.abort = function abort() { | ||
this._controllable.abort(); | ||
}; | ||
return RecoverableError; | ||
@@ -125,2 +125,3 @@ }(_es6Error2.default); | ||
notifier.callerId = this._id; | ||
notifier.onError(error, this._source.displayName); | ||
this._status.merge({ error: error, complete: false, pending: false }); | ||
@@ -127,0 +128,0 @@ var observer = this._updater; |
@@ -24,2 +24,5 @@ 'use strict'; | ||
notifier.trace = trace; | ||
if (!ref.cached) { | ||
ref.get(); | ||
} | ||
@@ -48,2 +51,5 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
notifier.trace = trace; | ||
if (!ref.cached) { | ||
ref.get(); | ||
} | ||
@@ -145,3 +151,3 @@ for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
} else if (typeof propName === 'string' && propName[0] !== '_') { | ||
if ((typeof prop === 'undefined' ? 'undefined' : _typeof(prop)) === 'object' && prop.__rdiSetter) { | ||
if (prop && (typeof prop === 'undefined' ? 'undefined' : _typeof(prop)) === 'object' && prop.__rdiSetter) { | ||
prop.displayName = ref.displayName + '.' + propName; | ||
@@ -148,0 +154,0 @@ result[propName] = prop; |
{ | ||
"name": "reactive-di", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Reactive dependency injection", | ||
@@ -61,6 +61,6 @@ "publishConfig": { | ||
"devDependencies": { | ||
"babel-cli": "^6.18.0", | ||
"babel-core": "^6.21.0", | ||
"babel-cli": "^6.22.2", | ||
"babel-core": "^6.22.1", | ||
"babel-loader": "^6.2.10", | ||
"babel-plugin-espower": "^2.3.1", | ||
"babel-plugin-espower": "^2.3.2", | ||
"babel-plugin-module-resolver": "^2.4.0", | ||
@@ -70,34 +70,34 @@ "babel-plugin-syntax-decorators": "^6.13.0", | ||
"babel-plugin-transform-decorators-legacy": "^1.3.4", | ||
"babel-plugin-transform-flow-strip-types": "^6.21.0", | ||
"babel-plugin-transform-flow-strip-types": "^6.22.0", | ||
"babel-plugin-transform-metadata": "^2.0.2", | ||
"babel-polyfill": "^6.20.0", | ||
"babel-preset-babili": "0.0.9", | ||
"babel-preset-es2015": "^6.18.0", | ||
"babel-preset-react": "^6.16.0", | ||
"babel-preset-stage-0": "^6.16.0", | ||
"babel-polyfill": "^6.22.0", | ||
"babel-preset-babili": "0.0.10", | ||
"babel-preset-es2015": "^6.22.0", | ||
"babel-preset-react": "^6.22.0", | ||
"babel-preset-stage-0": "^6.22.0", | ||
"eslint-config-airplus": "^2.0.10", | ||
"flow-bin": "^0.37.4", | ||
"flow-bin": "^0.38.0", | ||
"glob": "^7.1.1", | ||
"html-webpack-plugin": "^2.24.1", | ||
"husky": "^0.12.0", | ||
"inferno": "^0.7.27", | ||
"inferno-component": "^0.7.27", | ||
"inferno-create-element": "^0.7.27", | ||
"inferno-dom": "^0.7.27", | ||
"jsdom": "^9.9.1", | ||
"jss": "^6.1.0", | ||
"html-webpack-plugin": "^2.28.0", | ||
"husky": "^0.13.1", | ||
"inferno": "^1.2.2", | ||
"inferno-component": "^1.2.2", | ||
"inferno-create-element": "^1.2.2", | ||
"inferno-dom": "^1.0.7", | ||
"jsdom": "^9.10.0", | ||
"jss": "^6.2.0", | ||
"jss-camel-case": "^3.0.0", | ||
"mocha": "^3.2.0", | ||
"power-assert": "^1.4.2", | ||
"react": "^15.4.1", | ||
"react-addons-test-utils": "^15.4.1", | ||
"react-dom": "^15.4.1", | ||
"sinon": "^1.17.6", | ||
"webpack": "^1.14.0", | ||
"webpack-dev-server": "^1.16.2" | ||
"react": "^15.4.2", | ||
"react-addons-test-utils": "^15.4.2", | ||
"react-dom": "^15.4.2", | ||
"sinon": "^1.17.7", | ||
"webpack": "^2.2.1", | ||
"webpack-dev-server": "^2.3.0" | ||
}, | ||
"dependencies": { | ||
"derivable": "^0.12.1", | ||
"es6-error": "^4.0.0" | ||
"es6-error": "^4.0.1" | ||
} | ||
} |
@@ -24,6 +24,4 @@ // @flow | ||
componentWillMount() { | ||
this._consumer = this.constructor.__factory.create( | ||
(this: IHasForceUpdate<Props>), | ||
this.props | ||
) | ||
this._consumer = this.constructor.__factory.create((this: IHasForceUpdate<Props>)) | ||
this._consumer.willMount(this.props) | ||
} | ||
@@ -30,0 +28,0 @@ |
@@ -21,3 +21,3 @@ // @flow | ||
if (args.length) { | ||
target._rdiArgs = args | ||
target._rdiArg = args | ||
} | ||
@@ -50,2 +50,3 @@ return target | ||
target._rdiKey = rec.key | ||
target._rdiConstr = rec.construct || false | ||
target._rdiInst = rec.instance || false | ||
@@ -52,0 +53,0 @@ target._rdiLoaded = rec.loaded || false |
@@ -92,3 +92,5 @@ // @flow | ||
this._errorComponent = meta.errorComponent | ||
? context.resolveConsumer(meta.errorComponent).create(fakeUpdater, {}) | ||
? context | ||
.resolveConsumer(meta.errorComponent) | ||
.create(fakeUpdater) | ||
: null | ||
@@ -121,3 +123,3 @@ | ||
this.state = this.cached = this._argVals[0] | ||
if (!this._args || resolveArgs(this._args, this._argVals)) { | ||
if (!this._args || resolveArgs(this._args, (this._argVals: any))) { | ||
const updaters = this._updaters | ||
@@ -137,3 +139,3 @@ for (let i = 0, l = updaters.length; i < l; i++) { | ||
} catch (e) { | ||
this.context.errorHandler.setError(e) | ||
this.context.notifier.onError(e, this.displayName) | ||
} | ||
@@ -195,3 +197,3 @@ } | ||
if (this._args) { | ||
resolveArgs(this._args, this._argVals) | ||
resolveArgs(this._args, (this._argVals: any)) | ||
} | ||
@@ -198,0 +200,0 @@ this.state = this.cached = this._argVals[0] |
@@ -39,4 +39,4 @@ // @flow | ||
create(updater: IHasForceUpdate<V>, props: V): IConsumerListener<V, Element, Component> { | ||
const listener = this._cached | ||
create(updater: IHasForceUpdate<V>): IConsumerListener<V, Element, Component> { | ||
return this._cached | ||
? this._cached.create(updater) | ||
@@ -47,7 +47,3 @@ : (new Consumer( | ||
)).create(updater) | ||
listener.willMount(props) | ||
return listener | ||
} | ||
} |
@@ -31,5 +31,5 @@ // @flow | ||
cached: ?Props | ||
props: Props | ||
_context: IContext | ||
_props: Props | ||
_lastProps: ?Props | ||
@@ -68,3 +68,3 @@ _hook: IGetable<IConsumerHook<Props>> | ||
this._lastError = null | ||
this._props = (null: any) | ||
this.props = (null: any) | ||
this._lastProps = null | ||
@@ -80,3 +80,3 @@ this._hook = hook | ||
this._lastError = e | ||
this._context.errorHandler.setError(e) | ||
this._context.notifier.onError(e, this.displayName) | ||
} | ||
@@ -89,5 +89,5 @@ | ||
} | ||
const hook: any = this._hook | ||
try { | ||
(this._hook: any).willUpdate(props, oldProps) | ||
(hook.cached || hook.get()).willUpdate(props, oldProps) | ||
} catch (e) { | ||
@@ -100,6 +100,8 @@ this._setError(e) | ||
this._lastProps = null | ||
this._lastState = null | ||
this._props = {...this._props, item: newItem} | ||
this._context.notifier.notify([this], this, this._props) | ||
this._updater.setProps(this._props) | ||
// this._lastState = null | ||
const newProps = {...this.props, item: newItem} | ||
if (this.shouldUpdate(newProps)) { | ||
this._context.notifier.notify([this], this.displayName, this.props, newProps) | ||
this._updater.setProps(this.props) | ||
} | ||
} | ||
@@ -121,9 +123,12 @@ | ||
} | ||
const hasReceiveProps = !!(this._hook.cached || this._hook.get()).willUpdate | ||
if ((!oldProps && props) || (!props && oldProps)) { | ||
this._props = props | ||
this.props = props | ||
if (hasReceiveProps) { | ||
this._willUpdate(props, oldProps) | ||
} | ||
return true | ||
} | ||
const hasReceiveProps = !!(this._hook.cached || this._hook.get()).willUpdate | ||
@@ -136,3 +141,3 @@ let lpKeys: number = 0 | ||
} | ||
this._props = props | ||
this.props = props | ||
return true | ||
@@ -149,3 +154,3 @@ } | ||
} | ||
this._props = props | ||
this.props = props | ||
return true | ||
@@ -161,3 +166,3 @@ } | ||
if (hook.didMount) { | ||
hook.didMount(this._props) | ||
hook.didMount(this.props) | ||
} | ||
@@ -173,3 +178,3 @@ } catch (e) { | ||
if (hook.didUpdate) { | ||
hook.didUpdate(this._props) | ||
hook.didUpdate(this.props) | ||
} | ||
@@ -187,5 +192,6 @@ } catch (e) { | ||
console.error('Can\'t render error: error component is not defined') // eslint-disable-line | ||
throw error | ||
// throw error | ||
return (null: any) | ||
} | ||
errorComponent.shouldUpdate({error}) | ||
errorComponent.props = {error} | ||
return errorComponent.render() | ||
@@ -248,3 +254,3 @@ } | ||
} | ||
this._lastProps = this._props | ||
this._lastProps = this.props | ||
this._lastState = this._parent.state | ||
@@ -256,3 +262,3 @@ try { | ||
const result = (this._proto.cached || this._proto.get())( | ||
this._props, | ||
this.props, | ||
this._lastState, | ||
@@ -274,7 +280,10 @@ (this: IHasCreateComponent<Element>) | ||
if (hook.willUnmount) { | ||
hook.willUnmount(this._props) | ||
hook.willUnmount(this.props) | ||
} | ||
const prop = this._props.item | ||
if (prop && (prop: Object)[itemKey]) { | ||
(prop: Object)[itemKey].listener = fakeListener | ||
const prop = this.props.item | ||
if (prop) { | ||
const p = (prop: Object)[itemKey] | ||
if (p && p.listener === this) { | ||
p.listener = fakeListener | ||
} | ||
} | ||
@@ -287,3 +296,3 @@ } catch (e) { | ||
willMount(props: Props): void { | ||
this._props = props | ||
this.props = props | ||
const prop = props.item | ||
@@ -297,3 +306,3 @@ if (prop && (prop: Object)[itemKey]) { | ||
if (hook.willMount) { | ||
hook.willMount(this._props) | ||
hook.willMount(this.props) | ||
} | ||
@@ -300,0 +309,0 @@ } catch (e) { |
@@ -51,3 +51,3 @@ // @flow | ||
key, | ||
args: key._rdiArgs || null, | ||
args: key._rdiArg || null, | ||
hook: key._rdiHook || null, | ||
@@ -73,3 +73,3 @@ errorComponent: componentMeta.onError || key === this._defaultErrorComponent | ||
func: key._rdiFn || false, | ||
args: key._rdiArgs || null, | ||
args: key._rdiArg || null, | ||
ender: key._rdiEnd || isHook || false, | ||
@@ -84,2 +84,3 @@ hook: key._rdiHook || null | ||
const instance = !!key._rdiInst | ||
const construct = !!key._rdiConstr | ||
const name = key._rdiKey || debugName(key) | ||
@@ -91,3 +92,5 @@ const configValue = this._values[name] || null | ||
? configValue | ||
: Object.assign(new key(), configValue) // eslint-disable-line | ||
: construct | ||
? new (key: any)(configValue) // eslint-disable-line | ||
: Object.assign(new key(), configValue) // eslint-disable-line | ||
} else { | ||
@@ -94,0 +97,0 @@ initialValue = (new key(): any) // eslint-disable-line |
@@ -81,2 +81,3 @@ // @flow | ||
closed: boolean; | ||
props: Props; | ||
willUnmount(): void; | ||
@@ -95,3 +96,3 @@ willMount(prop: Props): void; | ||
context: IContext; | ||
create(updater: IHasForceUpdate<Props>, props: Props): IConsumerListener<Props, Element, Component>; | ||
create(updater: IHasForceUpdate<Props>): IConsumerListener<Props, Element, Component>; | ||
} | ||
@@ -228,4 +229,7 @@ | ||
export type ICallerInfo = { | ||
export type ICallerInfo<V> = { | ||
trace: string; | ||
modelName: string; | ||
oldValue: ?V; | ||
newValue: V; | ||
asyncType: null | 'next' | 'error' | 'complete'; | ||
@@ -235,11 +239,18 @@ callerId: number; | ||
export type IMiddlewares = { | ||
onSetValue<V>(src: IDepInfo<V>, newVal: V, trace: ICallerInfo): void; | ||
export type ILogger = { | ||
onError(error: Error, name: string): void; | ||
onSetValue<V>(info: ICallerInfo<V>): void; | ||
} | ||
export type INotifier = ICallerInfo & { | ||
export type INotifier = { | ||
trace: string; | ||
callerId: number; | ||
asyncType: null | 'next' | 'error' | 'complete'; | ||
lastId: number; | ||
logger: ?IComputed<ILogger>; | ||
end(): void; | ||
notify<V>(c: IPullable<*>[], info: IDepInfo<V>, newVal: V): void; | ||
onError(e: Error, name: string): void; | ||
notify<V>(c: IPullable<*>[], name: string, oldValue: V, newValue: V): void; | ||
} | ||
@@ -259,6 +270,2 @@ | ||
export interface IErrorHandler { | ||
setError(e: Error): void; | ||
} | ||
export type IStaticContext<Component, Element> = { | ||
@@ -269,3 +276,2 @@ binder: IRelationBinder; | ||
componentFactory: IComponentFactory<*, *>; | ||
errorHandler: IErrorHandler; | ||
protoFactory: ?IContext; | ||
@@ -288,3 +294,2 @@ contexts: ?IDisposableCollection<IContext>; | ||
componentFactory: IComponentFactory<Component, *>; | ||
errorHandler: IErrorHandler; | ||
protoFactory: ?IContext; | ||
@@ -350,1 +355,4 @@ binder: IRelationBinder; | ||
} | ||
export type ResultOf<F> = _ResultOf<*, F> | ||
type _ResultOf<V, F: (...x: any[]) => V> = V // eslint-disable-line |
@@ -36,2 +36,3 @@ // @flow | ||
_parent: ?ISource<*> | ||
isResolving: boolean | ||
@@ -57,4 +58,5 @@ constructor( | ||
this.cached = meta.initialValue | ||
this._hook = this.context.resolveHook(meta.hook) | ||
this._meta = meta | ||
this.isResolving = !!meta.hook | ||
this._hook = !meta.hook ? context.resolveHook(null) : (null: any) | ||
this._isFetching = meta.isFetching | ||
@@ -64,6 +66,8 @@ this._isPending = meta.isPending | ||
willMount(_parent: ?IContext): void { | ||
willMount(parent: ?IContext): void { | ||
if (this._parent) { | ||
if (!this._parent.refs) { | ||
this._parent.willMount(parent) | ||
} | ||
this._parent.refs++ | ||
this._parent.willMount(_parent) | ||
} | ||
@@ -97,2 +101,10 @@ const hook = this._hook.cached || this._hook.get() | ||
resolve(): void { | ||
if (this.isResolving) { | ||
this.isResolving = false | ||
if (!this._hook) { | ||
this._hook = this.context.resolveHook(this._meta.hook) | ||
} | ||
// return | ||
} | ||
const {stack, level} = this.context.binder | ||
@@ -107,4 +119,4 @@ let source: ISource<any> = this | ||
if (!rec.has[source.id]) { | ||
rec.has[source.id] = true | ||
if (rec.v.t === 3) { // status | ||
rec.has[source.id] = true | ||
if (isFetching) { | ||
@@ -118,2 +130,3 @@ source = this.status || this.getStatus() | ||
} else if (i >= level || source !== this) { | ||
rec.has[source.id] = true | ||
// consumer or computed | ||
@@ -184,5 +197,5 @@ if (rec.v.t === 2) { // consumer | ||
} | ||
context.notifier.notify(this.consumers.items, this, v) | ||
context.notifier.notify(this.consumers.items, this.displayName, this.cached, v) | ||
this.cached = v | ||
} | ||
} |
// @flow | ||
import type {IMiddlewares, IDepInfo, IPullable} from './interfaces' | ||
import type {IComputed, ILogger, IPullable} from './interfaces' | ||
export default class Transact<C: IPullable<*>> { | ||
_consumers: C[] = [] | ||
_middlewares: ?IMiddlewares | ||
logger: ?IComputed<ILogger> | ||
trace: string = '' | ||
@@ -14,9 +14,3 @@ asyncType: null | 'next' | 'error' | 'complete' = null | ||
constructor( | ||
middlewares?: ?IMiddlewares | ||
) { | ||
this._middlewares = middlewares | ||
} | ||
notify<V>(consumers: C[], info: IDepInfo<V>, value: V): void { | ||
notify<V>(consumers: C[], modelName: string, oldValue: V, newValue: V): void { | ||
const ac = this._consumers | ||
@@ -26,14 +20,25 @@ this._consumers = ac.length | ||
: consumers | ||
if (this._middlewares) { | ||
this._middlewares.onSetValue( | ||
info, | ||
value, | ||
this | ||
) | ||
if (this.logger) { | ||
this.logger.get().onSetValue({ | ||
trace: this.trace, | ||
callerId: this.callerId, | ||
asyncType: this.asyncType, | ||
modelName, | ||
oldValue, | ||
newValue | ||
}) | ||
} | ||
} | ||
onError(e: Error, name: string) { | ||
if (this.logger) { | ||
this.logger.get().onError(e, name) | ||
} | ||
} | ||
end(): void { | ||
if (!this.trace) { | ||
const consumers = this._consumers | ||
// consumer.pull can recursively run Transact.end, protect from this | ||
this._consumers = [] | ||
for (let i = 0, l = consumers.length; i < l; i++) { | ||
@@ -45,5 +50,4 @@ const consumer = consumers[i] | ||
} | ||
this._consumers = [] | ||
} | ||
} | ||
} |
@@ -6,3 +6,2 @@ // @flow | ||
IComponentFactory, | ||
IErrorHandler, | ||
IContext, | ||
@@ -40,3 +39,2 @@ IRelationBinder, | ||
componentFactory: IComponentFactory<Component, Element> | ||
errorHandler: IErrorHandler | ||
protoFactory: ?IContext | ||
@@ -63,3 +61,2 @@ binder: IRelationBinder | ||
this.componentFactory = c.componentFactory | ||
this.errorHandler = c.errorHandler | ||
this.protoFactory = c.protoFactory | ||
@@ -189,2 +186,9 @@ this.binder = c.binder | ||
resolveComputed<V>(key: IKey): IComputed<V> { | ||
const rec: IComputed<V> = this._depFactory.computed(key, this) | ||
rec.resolve() | ||
return rec | ||
} | ||
resolveHook<V>(key: ?IKey): IComputed<V> { | ||
@@ -191,0 +195,0 @@ if (!key) { |
@@ -8,4 +8,3 @@ // @flow | ||
IKey, | ||
IMiddlewares, | ||
IErrorHandler | ||
ILogger | ||
} from './atoms/interfaces' | ||
@@ -24,17 +23,11 @@ | ||
defaultErrorComponent: IKey; | ||
errorHandler?: IErrorHandler; | ||
themeFactory: SheetFactory, | ||
componentFactory: IComponentFactory<Component, Element>; | ||
debug?: boolean; | ||
middlewares?: IMiddlewares; | ||
logger?: Class<ILogger>; | ||
} | ||
class DefaultErrorHandler { | ||
setError(e: Error): void { | ||
console.error(e) // eslint-disable-line | ||
} | ||
} | ||
export default class DiFactory<Component, Element> { | ||
_staticContext: IStaticContext<Component, Element> | ||
_loggerKey: ?IKey | ||
@@ -44,8 +37,8 @@ constructor(opts: IOpts<Component, Element>) { | ||
values.AbstractSheetFactory = opts.themeFactory | ||
this._loggerKey = opts.logger || null | ||
const context: IStaticContext<Component, Element> = this._staticContext = { | ||
depFactory: new DepFactory(values, opts.defaultErrorComponent), | ||
notifier: new Transact(opts.middlewares || null), | ||
notifier: new Transact(), | ||
componentFactory: opts.componentFactory, | ||
binder: new RelationBinder(), | ||
errorHandler: opts.errorHandler || new DefaultErrorHandler(), | ||
protoFactory: null, | ||
@@ -60,3 +53,8 @@ contexts: opts.debug ? new DisposableCollection() : null | ||
create(): Di<Component, Element> { | ||
return new Di('root', [], this._staticContext, []) | ||
const di = new Di('root', [], this._staticContext, []) | ||
if (this._loggerKey) { | ||
this._staticContext.notifier.logger = di.resolveComputed(this._loggerKey) | ||
} | ||
return di | ||
} | ||
@@ -63,0 +61,0 @@ |
@@ -11,3 +11,3 @@ // @flow | ||
import {setter, eventSetter} from './utils/wrapObject' | ||
import {setterKey} from './atoms/interfaces' | ||
import SourceStatus from './atoms/SourceStatus' | ||
@@ -21,2 +21,3 @@ import ReactComponentFactory from './adapters/ReactComponentFactory' | ||
setter, | ||
setterKey, | ||
eventSetter, | ||
@@ -39,5 +40,5 @@ refsSetter, | ||
IRawArg, | ||
IErrorHandler, | ||
IMiddlewares, | ||
IDepInfo | ||
ILogger, | ||
IDepInfo, | ||
ResultOf | ||
} from './atoms/interfaces' | ||
@@ -44,0 +45,0 @@ |
@@ -10,3 +10,3 @@ // @flow | ||
static _rdiArgs = [AbstractSheetFactory] | ||
static _rdiArg = [AbstractSheetFactory] | ||
@@ -13,0 +13,0 @@ constructor(sheetFactory: AbstractSheetFactory) { |
@@ -21,2 +21,8 @@ // @flow | ||
commit(): this { | ||
(this: any)[setterKey].set(this) | ||
return this | ||
} | ||
reset(): this { | ||
@@ -23,0 +29,0 @@ const val = new this.constructor() |
@@ -45,3 +45,3 @@ // @flow | ||
get(ids: string[]): Item[] { | ||
pick(ids: string[]): Item[] { | ||
const map = this._map | ||
@@ -48,0 +48,0 @@ const result: Item[] = [] |
@@ -6,4 +6,4 @@ /* @flow */ | ||
export type MapFn<T, V> = (v: T, index?: number) => V | ||
export type FilterFn<T> = (v: T, index?: number) => boolean | ||
export type MapFn<T, V> = (v: T, index: number) => V | ||
export type FilterFn<T> = (v: T, index: number) => boolean | ||
export type SortFn<T> = (a: T, b: T) => number | ||
@@ -26,3 +26,3 @@ export type FindFn<T> = (element: T, index?: number, arr?: T[], thisArg?: Object) => boolean | ||
export interface IIndexer<V> { | ||
export interface IIndexer<V, Id> { | ||
removeAll(): void; | ||
@@ -32,12 +32,15 @@ add(item: V, index: number): void; | ||
update(newItem: V, oldItem: ?V, index: number): void; | ||
pick(ids: Id[]): V[]; | ||
} | ||
export default class IndexCollection<Item: Object, Indexer: IIndexer<Item>> { | ||
export default class IndexCollection<Item: Object, Id, Indexer: IIndexer<Item, Id>> { | ||
// @@iterator(): Iterator<Item>; | ||
_items: Item[] | ||
_indexer: Indexer | ||
length: number | ||
indexer: Indexer | ||
static Item: Class<Item> | ||
static Indexer: ?Class<Indexer> | ||
static autoNotify: ?boolean | ||
@@ -48,11 +51,11 @@ constructor(recs?: ?$Shape<Item>[], newItems?: ?Item[], indexer?: ?Indexer) { | ||
const Idxr = this.constructor.Indexer | ||
this.indexer = indexer || (Idxr ? new Idxr() : new (IdIndexer: any)()) | ||
this._indexer = indexer || (Idxr ? new Idxr() : new (IdIndexer: any)()) | ||
} | ||
copy(items: $Shape<Item>[]): this { | ||
return new this.constructor(items, null, this.indexer) | ||
return new this.constructor(items, null, this._indexer) | ||
} | ||
_copy(items: Item[]): this { | ||
const newObj = new this.constructor(null, items, this.indexer) | ||
const newObj = new this.constructor(null, items, this._indexer) | ||
const source = (newObj: any)[setterKey] = (this: any)[setterKey] | ||
@@ -64,2 +67,8 @@ | ||
_notify(items?: Item[]): this { | ||
return this.constructor.autoNotify | ||
? this._copy(items || this._items) | ||
: this | ||
} | ||
_recsToItems(recs: $Shape<Item>[]): Item[] { | ||
@@ -86,4 +95,4 @@ const protoItem = new this.constructor.Item() | ||
removeAll(): this { | ||
if (this.indexer) { | ||
this.indexer.removeAll() | ||
if (this._indexer) { | ||
this._indexer.removeAll() | ||
} | ||
@@ -97,2 +106,10 @@ return this._copy([]) | ||
pick(ids: Id[]): Item[] { | ||
if (!this._indexer) { | ||
throw new Error('Indexer not implemented') | ||
} | ||
return this._indexer.pick(ids) | ||
} | ||
remove(ptr: Item, count?: number): this { | ||
@@ -103,6 +120,4 @@ const index: number = ptr[itemKey].i | ||
items.splice(index, cnt) | ||
if (this.indexer) { | ||
const indexer = this.indexer | ||
if (this._indexer) { | ||
const indexer = this._indexer | ||
for (let i = index, l = index + cnt; i < l; i++) { | ||
@@ -116,3 +131,5 @@ indexer.remove(items[i], i) | ||
} | ||
return this._copy(this._items) | ||
items.splice(index, cnt) | ||
return this._copy(items) | ||
} | ||
@@ -122,6 +139,6 @@ | ||
const index: number = ptr[itemKey].i | ||
this._items.splice(index, 0, ...newItems) | ||
const items = this._items | ||
items.splice(index, 0, ...newItems) | ||
let cnt: number = index | ||
const indexer = this.indexer | ||
const indexer = this._indexer | ||
const nl = indexer ? index + newItems.length : 0 | ||
@@ -135,3 +152,3 @@ for (let i = index, l = items.length; i < l; i++) { | ||
} | ||
return this._copy(this._items) | ||
return this._copy(items) | ||
} | ||
@@ -143,8 +160,9 @@ | ||
set(ptr: Item, newItem: Item): this { | ||
set(ptr: Item, ni?: Item): this { | ||
const index: number = ptr[itemKey].i | ||
const newItem = ni || ptr | ||
const item = this._items[index] | ||
if (item !== newItem) { | ||
if (this.indexer) { | ||
this.indexer.update(newItem, item, index) | ||
if (this._indexer) { | ||
this._indexer.update(newItem, item, index) | ||
} | ||
@@ -155,3 +173,4 @@ this._items[index] = newItem | ||
} | ||
return this | ||
return this._notify() | ||
} | ||
@@ -172,4 +191,4 @@ | ||
if (oldItem !== newItem || !updateFn) { | ||
if (this.indexer) { | ||
this.indexer.update(newItem, oldItem, index) | ||
if (this._indexer) { | ||
this._indexer.update(newItem, oldItem, index) | ||
} | ||
@@ -180,3 +199,4 @@ this._items[index] = newItem | ||
} | ||
return this | ||
return this._notify() | ||
} | ||
@@ -186,3 +206,3 @@ | ||
const items: Item[] = this._items | ||
const indexer = this.indexer | ||
const indexer = this._indexer | ||
for (let i = 0, l = items.length; i < l; i++) { | ||
@@ -201,3 +221,3 @@ const item = items[i] | ||
return this | ||
return this._notify() | ||
} | ||
@@ -207,3 +227,3 @@ | ||
const items: Item[] = this._items | ||
const indexer = this.indexer | ||
const indexer = this._indexer | ||
for (let i = 0, l = items.length; i < l; i++) { | ||
@@ -224,3 +244,3 @@ const item = items[i] | ||
return this | ||
return this._notify() | ||
} | ||
@@ -234,4 +254,4 @@ | ||
} | ||
if (this.indexer) { | ||
this.indexer.add(item, i) | ||
if (this._indexer) { | ||
this._indexer.add(item, i) | ||
} | ||
@@ -245,4 +265,4 @@ | ||
const item = this._items.pop() | ||
if (this.indexer) { | ||
this.indexer.remove(item, this._items.length) | ||
if (this._indexer) { | ||
this._indexer.remove(item, this._items.length) | ||
} | ||
@@ -260,8 +280,27 @@ return this._copy(this._items) | ||
filter(filterFn: FilterFn<Item>): Item[] { | ||
return this._items.filter(filterFn) | ||
filter(filterFn: FilterFn<Item>): this { | ||
const indexer = this._indexer | ||
const items = this._items | ||
const newItems: Item[] = [] | ||
for (let i = 0, j = 0, l = items.length; i < l; i++) { | ||
const item = items[i] | ||
item[itemKey].i = j | ||
if (filterFn(item, i)) { | ||
newItems.push(item) | ||
j++ | ||
} else { | ||
indexer.remove(item, i) | ||
} | ||
} | ||
return this._copy(newItems) | ||
} | ||
sort(sortFn: SortFn<Item>): Item[] { | ||
return this._items.sort(sortFn) | ||
sort(sortFn: SortFn<Item>): this { | ||
const sorted = this._items.sort(sortFn) | ||
for (let i = 0, l = sorted.length; i < l; i++) { | ||
sorted[i][itemKey].i = i | ||
} | ||
return this._copy(sorted) | ||
} | ||
@@ -268,0 +307,0 @@ } |
@@ -30,7 +30,7 @@ // @flow | ||
retry(): void { | ||
retry = () => { | ||
this._controllable.run() | ||
} | ||
abort(): void { | ||
abort = () => { | ||
this._controllable.abort() | ||
@@ -55,3 +55,3 @@ } | ||
export default class Updater<V> { | ||
_source: ISettable<V> | ||
_source: ISettable<V> & {displayName: string} | ||
_status: ISettable<ISourceStatus> | ||
@@ -135,2 +135,3 @@ _updater: IUpdater<V> | ||
notifier.callerId = this._id | ||
notifier.onError(error, this._source.displayName) | ||
this._status.merge({error, complete: false, pending: false}) | ||
@@ -137,0 +138,0 @@ const observer = this._updater |
@@ -10,2 +10,4 @@ // @flow | ||
cachedSrc: V; | ||
cached: ?V; | ||
get(): V; | ||
notifier: INotifier; | ||
@@ -24,2 +26,5 @@ } | ||
notifier.trace = trace | ||
if (!ref.cached) { | ||
ref.get() | ||
} | ||
const result: R = fastCallMethod(ref.cachedSrc, ref.cachedSrc[name], args) | ||
@@ -43,2 +48,5 @@ notifier.trace = oldTrace | ||
notifier.trace = trace | ||
if (!ref.cached) { | ||
ref.get() | ||
} | ||
const result = fastCall(ref.cachedSrc, args) // eslint-disable-line | ||
@@ -147,3 +155,3 @@ notifier.trace = oldTrace | ||
} else if (typeof propName === 'string' && propName[0] !== '_') { | ||
if (typeof prop === 'object' && prop.__rdiSetter) { | ||
if (prop && typeof prop === 'object' && prop.__rdiSetter) { | ||
prop.displayName = `${ref.displayName}.${propName}` | ||
@@ -150,0 +158,0 @@ result[propName] = prop |
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
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
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
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
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
359797
4965
0
Updatedes6-error@^4.0.1