Comparing version 3.0.20 to 3.1.0
@@ -5,2 +5,7 @@ # Change Log | ||
<a name="3.1.0"></a> | ||
# [3.1.0](https://github.com/zerkalica/lom_atom/compare/v3.0.20...v3.1.0) (2017-12-22) | ||
<a name="3.0.20"></a> | ||
@@ -7,0 +12,0 @@ ## [3.0.20](https://github.com/zerkalica/lom_atom/compare/v3.0.19...v3.0.20) (2017-12-18) |
@@ -23,2 +23,3 @@ function _defineProperties(target, props) { | ||
var actionId = Symbol('lom_action'); | ||
var ATOM_STATUS_DESTROYED = 0; | ||
@@ -225,2 +226,88 @@ var ATOM_STATUS_OBSOLETE = 1; | ||
var Collection = | ||
/*#__PURE__*/ | ||
function () { | ||
function Collection(atom, indexes) { | ||
this._atom = atom; | ||
this._indexes = indexes || new Map(); | ||
if (indexes === undefined) this._recalcIndexes(0, 0); | ||
} | ||
var _proto = Collection.prototype; | ||
_proto._recalcIndexes = function _recalcIndexes(from, delta) { | ||
var indexes = this._indexes, | ||
items = this._atom.current; | ||
for (var i = from, l = items.length; i < l; i++) { | ||
indexes.set(items[i], i - delta); | ||
} | ||
}; | ||
_proto.replace = function replace(oldItem, newItem) { | ||
if (oldItem === newItem) return this; | ||
var indexes = this._indexes, | ||
items = this._atom.current; | ||
var index = indexes.get(oldItem); | ||
if (index === undefined) throw new Error('oldItem not found'); | ||
items[index] = newItem; | ||
indexes.delete(oldItem); | ||
indexes.set(newItem, index); | ||
this._atom.notify(); | ||
return this; | ||
}; // $FlowFixMe | ||
_proto.add = function add(item) { | ||
var indexes = this._indexes, | ||
items = this._atom.current; | ||
indexes.set(item, items.length); | ||
items.push(item); | ||
this._atom.notify(); | ||
return this; | ||
}; | ||
_proto.update = function update(cb) { | ||
var indexes = this._indexes, | ||
items = this._atom.current; | ||
for (var i = 0, l = items.length; i < l; i++) { | ||
var oldItem = items[i]; | ||
var newItem = cb(oldItem); | ||
items[i] = newItem; | ||
if (newItem !== oldItem) { | ||
indexes.delete(oldItem); | ||
indexes.set(newItem, i); | ||
} | ||
} | ||
this._atom.notify(); | ||
return this; | ||
}; | ||
_proto.delete = function _delete(item) { | ||
var indexes = this._indexes, | ||
items = this._atom.current; | ||
var index = indexes.get(item); | ||
if (index === undefined) return this; | ||
this._recalcIndexes(index, 1); | ||
items.splice(index, 1); | ||
indexes.delete(item); | ||
this._atom.notify(); | ||
return this; | ||
}; | ||
return Collection; | ||
}(); | ||
var handlers = new Map([[Array, function arrayHandler(target, source, stack) { | ||
@@ -302,2 +389,3 @@ var equal = target.length === source.length; | ||
this._retry = undefined; | ||
this._coll = undefined; | ||
this._keyHash = keyHash; | ||
@@ -355,2 +443,3 @@ this.key = key; | ||
this._retry = undefined; | ||
this._coll = undefined; | ||
}; | ||
@@ -461,2 +550,6 @@ | ||
_proto.notify = function notify() { | ||
if (this._slaves) this._slaves.forEach(obsoleteSlave); | ||
}; | ||
_proto.refresh = function refresh() { | ||
@@ -554,2 +647,10 @@ var masters = this._masters; | ||
_proto.getCollection = function getCollection() { | ||
if (this._coll === undefined) { | ||
this._coll = new Collection(this); | ||
} | ||
return this._coll; | ||
}; | ||
_createClass(Atom, [{ | ||
@@ -564,3 +665,9 @@ key: "displayName", | ||
function createAction(host, methodName, sync) { | ||
function createAction(fn, sync) { | ||
return createActionMethod({ | ||
fn: fn | ||
}, 'fn', sync); | ||
} | ||
function createActionMethod(host, methodName, sync) { | ||
function actionFn() { | ||
@@ -600,3 +707,11 @@ var args = arguments; | ||
} catch (e) { | ||
if (!(e instanceof AtomWait)) throw e; | ||
if (!(e instanceof AtomWait)) { | ||
var slave = defaultContext.current; | ||
if (slave) { | ||
slave.value(e, ATOM_FORCE_CACHE); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
@@ -607,2 +722,4 @@ | ||
actionFn[actionId] = true; | ||
setFunctionName(actionFn, getId(host, methodName)); | ||
@@ -618,8 +735,11 @@ return actionFn; | ||
scheduleNative(function () { | ||
var fn = function fn() { | ||
return action.apply(void 0, args); | ||
}); | ||
}; | ||
setFunctionName(fn, action.displayName + "_cb"); | ||
scheduleNative(fn); | ||
} | ||
deferedAction.displayName = action.displayName + "_defered"; | ||
setFunctionName(deferedAction, action.displayName + "_defered"); | ||
return deferedAction; | ||
@@ -642,3 +762,3 @@ } | ||
if (definingProperty) return this[hk].bind(this); | ||
var action = createAction(this, hk, sync); | ||
var action = createActionMethod(this, hk, sync); | ||
var actionFn = defer ? createDeferedAction(action) : action; | ||
@@ -836,2 +956,7 @@ definingProperty = true; | ||
function getCollResult(atom) { | ||
forceCache = ATOM_FORCE_NONE; | ||
return atom.getCollection(); | ||
} | ||
Object.defineProperties(mem, { | ||
@@ -850,2 +975,8 @@ cache: { | ||
}, | ||
getColl: { | ||
get: function get() { | ||
forceCache = ATOM_FORCE_RETRY; | ||
return getCollResult; | ||
} | ||
}, | ||
async: { | ||
@@ -916,3 +1047,3 @@ get: function get() { | ||
export { Atom, action, detached, mem, ConsoleLogger, defaultContext, AtomWait }; | ||
export { Atom, action, createAction, detached, mem, ConsoleLogger, defaultContext, AtomWait, actionId }; | ||
//# sourceMappingURL=lom_atom.es.js.map |
@@ -27,2 +27,3 @@ 'use strict'; | ||
var actionId = Symbol('lom_action'); | ||
var ATOM_STATUS_DESTROYED = 0; | ||
@@ -229,2 +230,88 @@ var ATOM_STATUS_OBSOLETE = 1; | ||
var Collection = | ||
/*#__PURE__*/ | ||
function () { | ||
function Collection(atom, indexes) { | ||
this._atom = atom; | ||
this._indexes = indexes || new Map(); | ||
if (indexes === undefined) this._recalcIndexes(0, 0); | ||
} | ||
var _proto = Collection.prototype; | ||
_proto._recalcIndexes = function _recalcIndexes(from, delta) { | ||
var indexes = this._indexes, | ||
items = this._atom.current; | ||
for (var i = from, l = items.length; i < l; i++) { | ||
indexes.set(items[i], i - delta); | ||
} | ||
}; | ||
_proto.replace = function replace(oldItem, newItem) { | ||
if (oldItem === newItem) return this; | ||
var indexes = this._indexes, | ||
items = this._atom.current; | ||
var index = indexes.get(oldItem); | ||
if (index === undefined) throw new Error('oldItem not found'); | ||
items[index] = newItem; | ||
indexes.delete(oldItem); | ||
indexes.set(newItem, index); | ||
this._atom.notify(); | ||
return this; | ||
}; // $FlowFixMe | ||
_proto.add = function add(item) { | ||
var indexes = this._indexes, | ||
items = this._atom.current; | ||
indexes.set(item, items.length); | ||
items.push(item); | ||
this._atom.notify(); | ||
return this; | ||
}; | ||
_proto.update = function update(cb) { | ||
var indexes = this._indexes, | ||
items = this._atom.current; | ||
for (var i = 0, l = items.length; i < l; i++) { | ||
var oldItem = items[i]; | ||
var newItem = cb(oldItem); | ||
items[i] = newItem; | ||
if (newItem !== oldItem) { | ||
indexes.delete(oldItem); | ||
indexes.set(newItem, i); | ||
} | ||
} | ||
this._atom.notify(); | ||
return this; | ||
}; | ||
_proto.delete = function _delete(item) { | ||
var indexes = this._indexes, | ||
items = this._atom.current; | ||
var index = indexes.get(item); | ||
if (index === undefined) return this; | ||
this._recalcIndexes(index, 1); | ||
items.splice(index, 1); | ||
indexes.delete(item); | ||
this._atom.notify(); | ||
return this; | ||
}; | ||
return Collection; | ||
}(); | ||
var handlers = new Map([[Array, function arrayHandler(target, source, stack) { | ||
@@ -306,2 +393,3 @@ var equal = target.length === source.length; | ||
this._retry = undefined; | ||
this._coll = undefined; | ||
this._keyHash = keyHash; | ||
@@ -359,2 +447,3 @@ this.key = key; | ||
this._retry = undefined; | ||
this._coll = undefined; | ||
}; | ||
@@ -465,2 +554,6 @@ | ||
_proto.notify = function notify() { | ||
if (this._slaves) this._slaves.forEach(obsoleteSlave); | ||
}; | ||
_proto.refresh = function refresh() { | ||
@@ -558,2 +651,10 @@ var masters = this._masters; | ||
_proto.getCollection = function getCollection() { | ||
if (this._coll === undefined) { | ||
this._coll = new Collection(this); | ||
} | ||
return this._coll; | ||
}; | ||
_createClass(Atom, [{ | ||
@@ -568,3 +669,9 @@ key: "displayName", | ||
function createAction(host, methodName, sync) { | ||
function createAction(fn, sync) { | ||
return createActionMethod({ | ||
fn: fn | ||
}, 'fn', sync); | ||
} | ||
function createActionMethod(host, methodName, sync) { | ||
function actionFn() { | ||
@@ -604,3 +711,11 @@ var args = arguments; | ||
} catch (e) { | ||
if (!(e instanceof AtomWait)) throw e; | ||
if (!(e instanceof AtomWait)) { | ||
var slave = defaultContext.current; | ||
if (slave) { | ||
slave.value(e, ATOM_FORCE_CACHE); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
@@ -611,2 +726,4 @@ | ||
actionFn[actionId] = true; | ||
setFunctionName(actionFn, getId(host, methodName)); | ||
@@ -622,8 +739,11 @@ return actionFn; | ||
scheduleNative(function () { | ||
var fn = function fn() { | ||
return action.apply(void 0, args); | ||
}); | ||
}; | ||
setFunctionName(fn, action.displayName + "_cb"); | ||
scheduleNative(fn); | ||
} | ||
deferedAction.displayName = action.displayName + "_defered"; | ||
setFunctionName(deferedAction, action.displayName + "_defered"); | ||
return deferedAction; | ||
@@ -646,3 +766,3 @@ } | ||
if (definingProperty) return this[hk].bind(this); | ||
var action = createAction(this, hk, sync); | ||
var action = createActionMethod(this, hk, sync); | ||
var actionFn = defer ? createDeferedAction(action) : action; | ||
@@ -840,2 +960,7 @@ definingProperty = true; | ||
function getCollResult(atom) { | ||
forceCache = ATOM_FORCE_NONE; | ||
return atom.getCollection(); | ||
} | ||
Object.defineProperties(mem, { | ||
@@ -854,2 +979,8 @@ cache: { | ||
}, | ||
getColl: { | ||
get: function get() { | ||
forceCache = ATOM_FORCE_RETRY; | ||
return getCollResult; | ||
} | ||
}, | ||
async: { | ||
@@ -922,2 +1053,3 @@ get: function get() { | ||
exports.action = action; | ||
exports.createAction = createAction; | ||
exports.detached = detached; | ||
@@ -928,2 +1060,3 @@ exports.mem = mem; | ||
exports.AtomWait = AtomWait; | ||
exports.actionId = actionId; | ||
//# sourceMappingURL=lom_atom.js.map |
@@ -29,2 +29,3 @@ (function (global, factory) { | ||
var actionId = Symbol('lom_action'); | ||
var ATOM_STATUS_DESTROYED = 0; | ||
@@ -231,2 +232,88 @@ var ATOM_STATUS_OBSOLETE = 1; | ||
var Collection = | ||
/*#__PURE__*/ | ||
function () { | ||
function Collection(atom, indexes) { | ||
this._atom = atom; | ||
this._indexes = indexes || new Map(); | ||
if (indexes === undefined) this._recalcIndexes(0, 0); | ||
} | ||
var _proto = Collection.prototype; | ||
_proto._recalcIndexes = function _recalcIndexes(from, delta) { | ||
var indexes = this._indexes, | ||
items = this._atom.current; | ||
for (var i = from, l = items.length; i < l; i++) { | ||
indexes.set(items[i], i - delta); | ||
} | ||
}; | ||
_proto.replace = function replace(oldItem, newItem) { | ||
if (oldItem === newItem) return this; | ||
var indexes = this._indexes, | ||
items = this._atom.current; | ||
var index = indexes.get(oldItem); | ||
if (index === undefined) throw new Error('oldItem not found'); | ||
items[index] = newItem; | ||
indexes.delete(oldItem); | ||
indexes.set(newItem, index); | ||
this._atom.notify(); | ||
return this; | ||
}; // $FlowFixMe | ||
_proto.add = function add(item) { | ||
var indexes = this._indexes, | ||
items = this._atom.current; | ||
indexes.set(item, items.length); | ||
items.push(item); | ||
this._atom.notify(); | ||
return this; | ||
}; | ||
_proto.update = function update(cb) { | ||
var indexes = this._indexes, | ||
items = this._atom.current; | ||
for (var i = 0, l = items.length; i < l; i++) { | ||
var oldItem = items[i]; | ||
var newItem = cb(oldItem); | ||
items[i] = newItem; | ||
if (newItem !== oldItem) { | ||
indexes.delete(oldItem); | ||
indexes.set(newItem, i); | ||
} | ||
} | ||
this._atom.notify(); | ||
return this; | ||
}; | ||
_proto.delete = function _delete(item) { | ||
var indexes = this._indexes, | ||
items = this._atom.current; | ||
var index = indexes.get(item); | ||
if (index === undefined) return this; | ||
this._recalcIndexes(index, 1); | ||
items.splice(index, 1); | ||
indexes.delete(item); | ||
this._atom.notify(); | ||
return this; | ||
}; | ||
return Collection; | ||
}(); | ||
var handlers = new Map([[Array, function arrayHandler(target, source, stack) { | ||
@@ -308,2 +395,3 @@ var equal = target.length === source.length; | ||
this._retry = undefined; | ||
this._coll = undefined; | ||
this._keyHash = keyHash; | ||
@@ -361,2 +449,3 @@ this.key = key; | ||
this._retry = undefined; | ||
this._coll = undefined; | ||
}; | ||
@@ -467,2 +556,6 @@ | ||
_proto.notify = function notify() { | ||
if (this._slaves) this._slaves.forEach(obsoleteSlave); | ||
}; | ||
_proto.refresh = function refresh() { | ||
@@ -560,2 +653,10 @@ var masters = this._masters; | ||
_proto.getCollection = function getCollection() { | ||
if (this._coll === undefined) { | ||
this._coll = new Collection(this); | ||
} | ||
return this._coll; | ||
}; | ||
_createClass(Atom, [{ | ||
@@ -570,3 +671,9 @@ key: "displayName", | ||
function createAction(host, methodName, sync) { | ||
function createAction(fn, sync) { | ||
return createActionMethod({ | ||
fn: fn | ||
}, 'fn', sync); | ||
} | ||
function createActionMethod(host, methodName, sync) { | ||
function actionFn() { | ||
@@ -606,3 +713,11 @@ var args = arguments; | ||
} catch (e) { | ||
if (!(e instanceof AtomWait)) throw e; | ||
if (!(e instanceof AtomWait)) { | ||
var slave = defaultContext.current; | ||
if (slave) { | ||
slave.value(e, ATOM_FORCE_CACHE); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
@@ -613,2 +728,4 @@ | ||
actionFn[actionId] = true; | ||
setFunctionName(actionFn, getId(host, methodName)); | ||
@@ -624,8 +741,11 @@ return actionFn; | ||
scheduleNative(function () { | ||
var fn = function fn() { | ||
return action.apply(void 0, args); | ||
}); | ||
}; | ||
setFunctionName(fn, action.displayName + "_cb"); | ||
scheduleNative(fn); | ||
} | ||
deferedAction.displayName = action.displayName + "_defered"; | ||
setFunctionName(deferedAction, action.displayName + "_defered"); | ||
return deferedAction; | ||
@@ -648,3 +768,3 @@ } | ||
if (definingProperty) return this[hk].bind(this); | ||
var action = createAction(this, hk, sync); | ||
var action = createActionMethod(this, hk, sync); | ||
var actionFn = defer ? createDeferedAction(action) : action; | ||
@@ -842,2 +962,7 @@ definingProperty = true; | ||
function getCollResult(atom) { | ||
forceCache = ATOM_FORCE_NONE; | ||
return atom.getCollection(); | ||
} | ||
Object.defineProperties(mem, { | ||
@@ -856,2 +981,8 @@ cache: { | ||
}, | ||
getColl: { | ||
get: function get() { | ||
forceCache = ATOM_FORCE_RETRY; | ||
return getCollResult; | ||
} | ||
}, | ||
async: { | ||
@@ -924,2 +1055,3 @@ get: function get() { | ||
exports.action = action; | ||
exports.createAction = createAction; | ||
exports.detached = detached; | ||
@@ -930,2 +1062,3 @@ exports.mem = mem; | ||
exports.AtomWait = AtomWait; | ||
exports.actionId = actionId; | ||
@@ -932,0 +1065,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
{ | ||
"name": "lom_atom", | ||
"version": "3.0.20", | ||
"version": "3.1.0", | ||
"description": "Alternative implementation of eigenmethod mol_atom state management library", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
@@ -22,2 +22,4 @@ // @flow | ||
import Collection from './Collection' | ||
function checkSlave(slave: IAtomInt) { | ||
@@ -47,3 +49,3 @@ slave.check() | ||
current: V | Error | ||
current: V | ||
_next: V | Error | void | ||
@@ -125,2 +127,3 @@ _suggested: V | Error | void | ||
this._retry = undefined | ||
this._coll = undefined | ||
} | ||
@@ -221,3 +224,3 @@ | ||
if (prev !== next) { | ||
this.current = next | ||
this.current = (next: any) | ||
this._context.newValue((this: IAtomInt), prev, next) | ||
@@ -228,2 +231,6 @@ if (this._slaves) this._slaves.forEach(obsoleteSlave) | ||
notify() { | ||
if (this._slaves) this._slaves.forEach(obsoleteSlave) | ||
} | ||
refresh(): void { | ||
@@ -310,2 +317,12 @@ const masters = this._masters | ||
} | ||
_coll: Collection<*> | void = undefined | ||
getCollection<T>(): Collection<T> { | ||
if (this._coll === undefined) { | ||
this._coll = new Collection((this: IAtom<any>)) | ||
} | ||
return this._coll | ||
} | ||
} |
// @flow | ||
import Collection from './Collection' | ||
export const handlers: Map<mixed, Function> = new Map([ | ||
@@ -4,0 +6,0 @@ [ |
// @flow | ||
import type {TypedPropertyDescriptor} from '../interfaces' | ||
import type {IAtomInt, TypedPropertyDescriptor} from '../interfaces' | ||
import {actionId, ATOM_FORCE_CACHE} from '../interfaces' | ||
import {scheduleNative, getId, setFunctionName, AtomWait} from '../utils' | ||
@@ -9,3 +10,11 @@ import {defaultContext} from '../Context' | ||
function createAction<Host: Object>(host: Host, methodName: string, sync?: boolean): (...args: any[]) => void { | ||
export function createAction<V: (...args: any[]) => void>(fn: V, sync?: boolean): V { | ||
return (createActionMethod({fn}, 'fn', sync): any) | ||
} | ||
function createActionMethod<Host: Object>( | ||
host: Host, | ||
methodName: string, | ||
sync?: boolean | ||
): (...args: any[]) => void { | ||
function actionFn(): void { | ||
@@ -24,6 +33,14 @@ const args = arguments | ||
} catch(e) { | ||
if (!(e instanceof AtomWait)) throw e | ||
if (!(e instanceof AtomWait)) { | ||
const slave = defaultContext.current | ||
if (slave) { | ||
slave.value(e, ATOM_FORCE_CACHE) | ||
} else { | ||
throw e | ||
} | ||
} | ||
} | ||
if (sync) defaultContext.sync() | ||
} | ||
;(actionFn: Object)[actionId] = true | ||
@@ -36,5 +53,7 @@ setFunctionName(actionFn, getId(host, methodName)) | ||
function deferedAction(...args: any[]) { | ||
scheduleNative(() => action(...args)) | ||
const fn = () => action(...args) | ||
setFunctionName(fn, `${action.displayName}_cb`) | ||
scheduleNative(fn) | ||
} | ||
deferedAction.displayName = `${action.displayName}_defered` | ||
setFunctionName(deferedAction, `${action.displayName}_defered`) | ||
@@ -64,3 +83,3 @@ return deferedAction | ||
const action = createAction(this, hk, sync) | ||
const action = createActionMethod(this, hk, sync) | ||
const actionFn = defer | ||
@@ -67,0 +86,0 @@ ? createDeferedAction(action) |
@@ -7,2 +7,3 @@ // @flow | ||
import Atom from '../Atom' | ||
import Collection from '../Collection' | ||
@@ -170,2 +171,7 @@ function createGetSetHandler<V>( | ||
function getCollResult<V>(atom: IAtom<V[]>): Collection<V> { | ||
forceCache = ATOM_FORCE_NONE | ||
return atom.getCollection() | ||
} | ||
Object.defineProperties(mem, { | ||
@@ -184,2 +190,8 @@ cache: ({ | ||
}: any), | ||
getColl: ({ | ||
get<V>(): (v: IAtom<V[]>) => Collection<V> { | ||
forceCache = ATOM_FORCE_RETRY | ||
return getCollResult | ||
} | ||
}: any), | ||
async: ({ | ||
@@ -207,4 +219,5 @@ get<V>(): (v: V) => V { | ||
getRetry<V>(v: V): () => void; | ||
getColl<V>(v: V[]): Collection<V>; | ||
key: IMemKey; | ||
} | ||
export default ((mem: any): IMem) |
// @flow | ||
export {default as Atom} from './Atom' | ||
export {default as action} from './decorators/action' | ||
export {default as action, createAction} from './decorators/action' | ||
export {default as detached} from './decorators/detached' | ||
@@ -11,2 +11,4 @@ export {default as mem} from './decorators/mem' | ||
export {actionId} from './interfaces' | ||
export type { | ||
@@ -13,0 +15,0 @@ IAtomHandler, |
// @flow | ||
import type Collection from './Collection' | ||
export type ILoggerStatus = 'waiting' | 'proposeToReap' | 'proposeToPull' | ||
export const actionId = Symbol('lom_action') | ||
export interface ILogger { | ||
@@ -45,3 +45,3 @@ beginGroup(name: string): void; | ||
status: IAtomStatus; | ||
current: V | Error; | ||
current: V; | ||
+field: string; | ||
@@ -53,2 +53,4 @@ +displayName: string; | ||
getRetry(): () => void; | ||
getCollection<T>(): Collection<T>; | ||
notify(): void; | ||
} | ||
@@ -55,0 +57,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
361496
25
3785