Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lom_atom

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lom_atom - npm Package Compare versions

Comparing version 4.0.3 to 4.0.4

5

CHANGELOG.md

@@ -5,2 +5,7 @@ # Change Log

<a name="4.0.4"></a>
## [4.0.4](https://github.com/zerkalica/lom_atom/compare/v4.0.3...v4.0.4) (2018-03-27)
<a name="4.0.3"></a>

@@ -7,0 +12,0 @@ ## [4.0.3](https://github.com/zerkalica/lom_atom/compare/v4.0.2...v4.0.3) (2018-03-26)

53

dist/lom_atom.es.js

@@ -184,5 +184,10 @@ var actionId = Symbol('lom_action');

var atomId = Symbol('lom_atom');
function isPromise(target) {
return target !== null && typeof target === 'object' && typeof target.then === 'function';
var debugId = Symbol('lom_debug');
function addInfo(info, obj) {
obj[debugId] = info;
return obj;
}
function getInfo(obj) {
return (obj && typeof obj === 'object' ? obj[debugId] : null) || (obj instanceof Error ? obj.message : null);
}
/**

@@ -193,3 +198,3 @@ * Can't extend Error

var AtomWait = function AtomWait(message, promise) {
var AtomWait = function AtomWait(message) {
var t = Error.call(this, message || '[Pending]') // super(message)

@@ -199,4 +204,3 @@ // $FlowFixMe new.target

t['__proto__'] = new.target.prototype;
t[catchedId] = undefined;
t.promise = promise;
t[catchedId] = true;
return t;

@@ -206,3 +210,5 @@ };

AtomWait.prototype.constructor = AtomWait;
var AtomWaitInt = AtomWait;
function isPromise(target) {
return target !== null && typeof target === 'object' && typeof target.then === 'function';
}
function getId(t, hk) {

@@ -388,3 +394,3 @@ return (t.constructor.displayName || t.constructor.name) + "." + hk;

if (next !== undefined && (normalized = this._conform(next, this._suggested)) !== this._suggested && (current instanceof Error || (normalized = this._conform(next, current)) !== current)) {
if (next !== undefined && (normalized = this._conform(next, this._suggested)) !== this._suggested && (current instanceof Error || isPromise(current) || (normalized = this._conform(next, current)) !== current)) {
this._suggested = this._next = normalized;

@@ -399,3 +405,3 @@ this.status = ATOM_STATUS_OBSOLETE;

if (current instanceof Error) {
if (current instanceof Error || isPromise(current)) {
if (forceCache !== ATOM_FORCE_NONE) {

@@ -450,3 +456,3 @@ if (current[proxyId] === undefined) current[proxyId] = proxify(current);

if (nextRaw instanceof Error) {
if (nextRaw instanceof Error || isPromise(nextRaw)) {
next = nextRaw[origId] === undefined ? nextRaw : nextRaw[origId];

@@ -491,18 +497,15 @@ if (next[atomId] === undefined) next[atomId] = this;

if (error[catchedId] === undefined) {
newValue = isPromise(error) ? new AtomWaitInt(undefined, error) : error;
newValue[catchedId] = true;
error[catchedId] = true;
if (newValue instanceof AtomWaitInt) {
var promise = newValue.promise;
if (promise) {
if (this._setForced === undefined) this._setForced = function (value) {
return _this.value(value, ATOM_FORCE_CACHE);
};
promise.then(this._setForced).catch(this._setForced);
}
if (isPromise(error)) {
if (this._setForced === undefined) this._setForced = function (value) {
return _this.value(value, ATOM_FORCE_CACHE);
};
error.then(this._setForced).catch(this._setForced);
} else {
console.error(newValue.stack || newValue);
console.error(error.stack || newValue);
}
} else newValue = error;
}
newValue = error;
}

@@ -676,3 +679,3 @@

} catch (e) {
if (!(e instanceof AtomWaitInt)) {
if (!isPromise(e)) {
var slave = defaultContext.current;

@@ -958,3 +961,3 @@

var _useColors = this._useColors;
console[from instanceof Error && !(from instanceof AtomWaitInt) ? 'warn' : to instanceof Error && !(to instanceof AtomWaitInt) ? 'error' : 'log'](_useColors ? '%c' + name : name, _useColors ? stringToColor(name) : '', from instanceof Error ? from.message : from, '➔', to instanceof Error ? to.message : to);
console[from instanceof Error && !isPromise(from) ? 'warn' : to instanceof Error && !isPromise(to) ? 'error' : 'log'](_useColors ? '%c' + name : name, _useColors ? stringToColor(name) : '', getInfo(from) || from, '➔', getInfo(to) || to);
}

@@ -966,3 +969,3 @@ };

export { Atom, ReactAtom, action, createAction, mem, ConsoleLogger, defaultContext, AtomWaitInt as AtomWait, actionId, defer };
export { Atom, ReactAtom, action, createAction, mem, ConsoleLogger, defaultContext, addInfo, getInfo, actionId, defer };
//# sourceMappingURL=lom_atom.es.js.map

@@ -188,5 +188,10 @@ 'use strict';

var atomId = Symbol('lom_atom');
function isPromise(target) {
return target !== null && typeof target === 'object' && typeof target.then === 'function';
var debugId = Symbol('lom_debug');
function addInfo(info, obj) {
obj[debugId] = info;
return obj;
}
function getInfo(obj) {
return (obj && typeof obj === 'object' ? obj[debugId] : null) || (obj instanceof Error ? obj.message : null);
}
/**

@@ -197,3 +202,3 @@ * Can't extend Error

var AtomWait = function AtomWait(message, promise) {
var AtomWait = function AtomWait(message) {
var t = Error.call(this, message || '[Pending]') // super(message)

@@ -203,4 +208,3 @@ // $FlowFixMe new.target

t['__proto__'] = new.target.prototype;
t[catchedId] = undefined;
t.promise = promise;
t[catchedId] = true;
return t;

@@ -210,3 +214,5 @@ };

AtomWait.prototype.constructor = AtomWait;
var AtomWaitInt = AtomWait;
function isPromise(target) {
return target !== null && typeof target === 'object' && typeof target.then === 'function';
}
function getId(t, hk) {

@@ -392,3 +398,3 @@ return (t.constructor.displayName || t.constructor.name) + "." + hk;

if (next !== undefined && (normalized = this._conform(next, this._suggested)) !== this._suggested && (current instanceof Error || (normalized = this._conform(next, current)) !== current)) {
if (next !== undefined && (normalized = this._conform(next, this._suggested)) !== this._suggested && (current instanceof Error || isPromise(current) || (normalized = this._conform(next, current)) !== current)) {
this._suggested = this._next = normalized;

@@ -403,3 +409,3 @@ this.status = ATOM_STATUS_OBSOLETE;

if (current instanceof Error) {
if (current instanceof Error || isPromise(current)) {
if (forceCache !== ATOM_FORCE_NONE) {

@@ -454,3 +460,3 @@ if (current[proxyId] === undefined) current[proxyId] = proxify(current);

if (nextRaw instanceof Error) {
if (nextRaw instanceof Error || isPromise(nextRaw)) {
next = nextRaw[origId] === undefined ? nextRaw : nextRaw[origId];

@@ -495,18 +501,15 @@ if (next[atomId] === undefined) next[atomId] = this;

if (error[catchedId] === undefined) {
newValue = isPromise(error) ? new AtomWaitInt(undefined, error) : error;
newValue[catchedId] = true;
error[catchedId] = true;
if (newValue instanceof AtomWaitInt) {
var promise = newValue.promise;
if (promise) {
if (this._setForced === undefined) this._setForced = function (value) {
return _this.value(value, ATOM_FORCE_CACHE);
};
promise.then(this._setForced).catch(this._setForced);
}
if (isPromise(error)) {
if (this._setForced === undefined) this._setForced = function (value) {
return _this.value(value, ATOM_FORCE_CACHE);
};
error.then(this._setForced).catch(this._setForced);
} else {
console.error(newValue.stack || newValue);
console.error(error.stack || newValue);
}
} else newValue = error;
}
newValue = error;
}

@@ -680,3 +683,3 @@

} catch (e) {
if (!(e instanceof AtomWaitInt)) {
if (!isPromise(e)) {
var slave = defaultContext.current;

@@ -962,3 +965,3 @@

var _useColors = this._useColors;
console[from instanceof Error && !(from instanceof AtomWaitInt) ? 'warn' : to instanceof Error && !(to instanceof AtomWaitInt) ? 'error' : 'log'](_useColors ? '%c' + name : name, _useColors ? stringToColor(name) : '', from instanceof Error ? from.message : from, '➔', to instanceof Error ? to.message : to);
console[from instanceof Error && !isPromise(from) ? 'warn' : to instanceof Error && !isPromise(to) ? 'error' : 'log'](_useColors ? '%c' + name : name, _useColors ? stringToColor(name) : '', getInfo(from) || from, '➔', getInfo(to) || to);
}

@@ -977,5 +980,6 @@ };

exports.defaultContext = defaultContext;
exports.AtomWait = AtomWaitInt;
exports.addInfo = addInfo;
exports.getInfo = getInfo;
exports.actionId = actionId;
exports.defer = defer;
//# sourceMappingURL=lom_atom.js.map

@@ -190,5 +190,10 @@ (function (global, factory) {

var atomId = Symbol('lom_atom');
function isPromise(target) {
return target !== null && typeof target === 'object' && typeof target.then === 'function';
var debugId = Symbol('lom_debug');
function addInfo(info, obj) {
obj[debugId] = info;
return obj;
}
function getInfo(obj) {
return (obj && typeof obj === 'object' ? obj[debugId] : null) || (obj instanceof Error ? obj.message : null);
}
/**

@@ -199,3 +204,3 @@ * Can't extend Error

var AtomWait = function AtomWait(message, promise) {
var AtomWait = function AtomWait(message) {
var t = Error.call(this, message || '[Pending]') // super(message)

@@ -205,4 +210,3 @@ // $FlowFixMe new.target

t['__proto__'] = new.target.prototype;
t[catchedId] = undefined;
t.promise = promise;
t[catchedId] = true;
return t;

@@ -212,3 +216,5 @@ };

AtomWait.prototype.constructor = AtomWait;
var AtomWaitInt = AtomWait;
function isPromise(target) {
return target !== null && typeof target === 'object' && typeof target.then === 'function';
}
function getId(t, hk) {

@@ -394,3 +400,3 @@ return (t.constructor.displayName || t.constructor.name) + "." + hk;

if (next !== undefined && (normalized = this._conform(next, this._suggested)) !== this._suggested && (current instanceof Error || (normalized = this._conform(next, current)) !== current)) {
if (next !== undefined && (normalized = this._conform(next, this._suggested)) !== this._suggested && (current instanceof Error || isPromise(current) || (normalized = this._conform(next, current)) !== current)) {
this._suggested = this._next = normalized;

@@ -405,3 +411,3 @@ this.status = ATOM_STATUS_OBSOLETE;

if (current instanceof Error) {
if (current instanceof Error || isPromise(current)) {
if (forceCache !== ATOM_FORCE_NONE) {

@@ -456,3 +462,3 @@ if (current[proxyId] === undefined) current[proxyId] = proxify(current);

if (nextRaw instanceof Error) {
if (nextRaw instanceof Error || isPromise(nextRaw)) {
next = nextRaw[origId] === undefined ? nextRaw : nextRaw[origId];

@@ -497,18 +503,15 @@ if (next[atomId] === undefined) next[atomId] = this;

if (error[catchedId] === undefined) {
newValue = isPromise(error) ? new AtomWaitInt(undefined, error) : error;
newValue[catchedId] = true;
error[catchedId] = true;
if (newValue instanceof AtomWaitInt) {
var promise = newValue.promise;
if (promise) {
if (this._setForced === undefined) this._setForced = function (value) {
return _this.value(value, ATOM_FORCE_CACHE);
};
promise.then(this._setForced).catch(this._setForced);
}
if (isPromise(error)) {
if (this._setForced === undefined) this._setForced = function (value) {
return _this.value(value, ATOM_FORCE_CACHE);
};
error.then(this._setForced).catch(this._setForced);
} else {
console.error(newValue.stack || newValue);
console.error(error.stack || newValue);
}
} else newValue = error;
}
newValue = error;
}

@@ -682,3 +685,3 @@

} catch (e) {
if (!(e instanceof AtomWaitInt)) {
if (!isPromise(e)) {
var slave = defaultContext.current;

@@ -964,3 +967,3 @@

var _useColors = this._useColors;
console[from instanceof Error && !(from instanceof AtomWaitInt) ? 'warn' : to instanceof Error && !(to instanceof AtomWaitInt) ? 'error' : 'log'](_useColors ? '%c' + name : name, _useColors ? stringToColor(name) : '', from instanceof Error ? from.message : from, '➔', to instanceof Error ? to.message : to);
console[from instanceof Error && !isPromise(from) ? 'warn' : to instanceof Error && !isPromise(to) ? 'error' : 'log'](_useColors ? '%c' + name : name, _useColors ? stringToColor(name) : '', getInfo(from) || from, '➔', getInfo(to) || to);
}

@@ -979,3 +982,4 @@ };

exports.defaultContext = defaultContext;
exports.AtomWait = AtomWaitInt;
exports.addInfo = addInfo;
exports.getInfo = getInfo;
exports.actionId = actionId;

@@ -982,0 +986,0 @@ exports.defer = defer;

{
"name": "lom_atom",
"version": "4.0.3",
"version": "4.0.4",
"description": "Alternative implementation of eigenmethod mol_atom state management library",

@@ -5,0 +5,0 @@ "publishConfig": {

@@ -12,4 +12,8 @@ # lom_atom

Usage examples with [reactive-di](https://github.com/zerkalica/reactive-di): [example source](https://github.com/zerkalica/rdi-examples), [demo](http://zerkalica.github.io/rdi-examples/), [todomvc benchmark](http://mol.js.org/app/bench/#bench=https%3A%2F%2Fzerkalica.github.io%2Ftodomvc%2Fbenchmark%2F/sample=preact-lom-rdi~preact-raw~preact-mobx)
Usage examples:
* [fiddle](https://jsfiddle.net/zerkalica/j8ds07mm/)
* [todomvc benchmark](http://mol.js.org/app/bench/#bench=https%3A%2F%2Fzerkalica.github.io%2Ftodomvc%2Fbenchmark%2F/sample=preact-lom-rdi~preact-raw~preact-mobx),
Install ``` npm install --save lom_atom ```

@@ -78,3 +82,3 @@

```js
import {mem} from 'lom_atom'
import {mem, addInfo} from 'lom_atom'

@@ -91,3 +95,3 @@ class TodoList {

throw new mem.Wait('Loading /todos...', promise)
throw new addInfo('Loading /todos...', promise)
}

@@ -125,3 +129,2 @@

* ``` throw new Promise(...) ``` - Load data and handle errors and pending State
* ``` throw new mem.Wait('Loading /todos...', promise) ``` - Add some debug info to fetching payload

@@ -128,0 +131,0 @@ ## Key-value

@@ -19,3 +19,3 @@ // @flow

import Context, {defaultContext} from './Context'
import {atomId, AtomWait, isPromise, setFunctionName, origId, catchedId, proxify} from './utils'
import {atomId, isPromise, setFunctionName, origId, catchedId, proxify} from './utils'
import conform, {processed} from './conform'

@@ -146,3 +146,3 @@

&& (
current instanceof Error
current instanceof Error || isPromise(current)
|| (normalized = this._conform(next, current)) !== current

@@ -159,3 +159,3 @@ )

current = this.current
if (current instanceof Error) {
if (current instanceof Error || isPromise(current)) {
if (forceCache !== ATOM_FORCE_NONE) {

@@ -208,8 +208,8 @@ if ((current: any)[proxyId] === undefined) (current: any)[proxyId] = proxify((current: any))

const prev: V | Error = this.current
let next: V | Error
if (nextRaw instanceof Error) {
next = (nextRaw: Object)[origId] === undefined
let next: V | Error | Promise<V>
if (nextRaw instanceof Error || isPromise(nextRaw)) {
next = (nextRaw: any)[origId] === undefined
? nextRaw
: (nextRaw: Object)[origId]
if ((next: Object)[atomId] === undefined) (next: Object)[atomId] = this
: (nextRaw: any)[origId]
if ((next: any)[atomId] === undefined) (next: any)[atomId] = this
} else {

@@ -251,18 +251,15 @@ next = this._conform(nextRaw, prev)

if ((error: Object)[catchedId] === undefined) {
newValue = isPromise(error) ? new AtomWait(undefined, (error: any)) : error
;(newValue: Object)[catchedId] = true
if (newValue instanceof AtomWait) {
const promise = newValue.promise
if (promise) {
if (this._setForced === undefined) this._setForced = value => {
return this.value(value, ATOM_FORCE_CACHE)
}
promise
.then(this._setForced)
.catch(this._setForced)
;(error: Object)[catchedId] = true
if (isPromise(error)) {
if (this._setForced === undefined) this._setForced = value => {
return this.value(value, ATOM_FORCE_CACHE)
}
error
.then(this._setForced)
.catch(this._setForced)
} else {
console.error(newValue.stack || newValue)
console.error(error.stack || newValue)
}
} else newValue = error
}
newValue = error
}

@@ -269,0 +266,0 @@ context.current = slave

// @flow
import type {IAtom, ILogger} from './interfaces'
import {AtomWait} from './utils'
import {getInfo, isPromise} from './utils'
import ReactAtom from './ReactAtom'

@@ -52,11 +52,11 @@

console[
from instanceof Error && !(from instanceof AtomWait)
from instanceof Error && !isPromise(from)
? 'warn'
: (to instanceof Error && !(to instanceof AtomWait) ? 'error' : 'log')
: (to instanceof Error && !isPromise(to) ? 'error' : 'log')
](
useColors ? '%c' + name : name,
useColors ? stringToColor(name) : '',
from instanceof Error ? from.message : from,
getInfo(from) || from,
'➔',
to instanceof Error ? to.message : to
getInfo(to) || to
)

@@ -63,0 +63,0 @@ }

@@ -5,3 +5,3 @@ // @flow

import {actionId, ATOM_FORCE_CACHE} from '../interfaces'
import {getId, setFunctionName, AtomWait} from '../utils'
import {getId, setFunctionName, isPromise} from '../utils'
import {defaultContext} from '../Context'

@@ -34,3 +34,3 @@ import defer from '../defer'

} catch(e) {
if (!(e instanceof AtomWait)) {
if (!isPromise(e)) {
const slave = defaultContext.current

@@ -37,0 +37,0 @@ if (slave) {

@@ -9,3 +9,3 @@ // @flow

export {defaultContext} from './Context'
export {AtomWait} from './utils'
export {addInfo, getInfo} from './utils'
// export {default as Collection} from './Collection'

@@ -12,0 +12,0 @@ export {actionId} from './interfaces'

@@ -6,6 +6,13 @@ // @flow

export function isPromise(target: mixed): boolean {
return target !== null && typeof target === 'object' && typeof target.then === 'function'
const debugId = Symbol('lom_debug')
export function addInfo<V: Object>(info: string, obj: V): V {
;(obj: Object)[debugId] = info
return obj
}
export function getInfo(obj: any): ?string {
return (obj && typeof obj === 'object' ? obj[debugId] : null) || (obj instanceof Error ? obj.message : null)
}
/**

@@ -18,5 +25,4 @@ * Can't extend Error

stack: string
promise: ?Promise<*>
constructor(message?: string, promise?: Promise<*>) {
constructor(message?: string) {
const t = Error.call(this, message || '[Pending]')

@@ -26,4 +32,3 @@ // super(message)

;(t: Object)['__proto__'] = new.target.prototype
;(t: Object)[catchedId] = undefined
;(t: Object).promise = promise
;(t: Object)[catchedId] = true
return t

@@ -39,2 +44,6 @@ }

export function isPromise(target: mixed): boolean {
return target !== null && typeof target === 'object' && typeof target.then === 'function'
}
export function getId(t: Object, hk: string): string {

@@ -41,0 +50,0 @@ return `${t.constructor.displayName || t.constructor.name}.${hk}`

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc