Comparing version 1.0.0-1532691371168 to 1.0.0-1532810720851
@@ -18,3 +18,3 @@ import { ActionBase, StopExecution } from 'action-chain'; | ||
const mutations = this.proxyStateTree.clearMutationTracking(); | ||
this.getActionChain().emit('mutations', Object.assign({ mutations }, effects.__execution)); | ||
this.getActionChain().emitAsync('mutations', Object.assign({ mutations }, effects.__execution)); | ||
return value; | ||
@@ -21,0 +21,0 @@ }; |
@@ -22,3 +22,3 @@ import { EventEmitter } from 'betsy'; | ||
} | ||
export default function computed<Config, NewValue>(cb: (config: Config) => (state: object) => NewValue, options?: ComputedOptions): (config: Config) => NewValue; | ||
export default function compute<Config, NewValue>(cb: (config: Config) => (state: object) => NewValue, options?: ComputedOptions): (config: Config) => NewValue; | ||
export {}; |
@@ -0,1 +1,2 @@ | ||
import { EventType } from './'; | ||
export class Computed { | ||
@@ -39,3 +40,3 @@ constructor(cb, options = {}) { | ||
cache.proxyStateTreeListener = proxyStateTree.addMutationListener(cache.paths, (flushId) => { | ||
eventHub.emit('computed:dirty', { | ||
eventHub.emitAsync(EventType.COMPUTED_DIRTY, { | ||
path, | ||
@@ -52,10 +53,11 @@ flushId, | ||
} | ||
eventHub.emit('computed', { | ||
eventHub.emitAsync(EventType.COMPUTED, { | ||
path, | ||
paths: Array.from(cache.paths), | ||
updateCount: cache.updateCount, | ||
value: cache.value, | ||
limit: this.cacheLimit, | ||
cacheKeysCount: this.cacheKeys.length, | ||
cacheKeyIndex: this.cacheKeys.indexOf(config), | ||
cache: Array.from(this.cache.values()).map((cache) => ({ | ||
value: cache.value, | ||
updateCount: cache.updateCount, | ||
paths: Array.from(cache.paths), | ||
})), | ||
}); | ||
@@ -70,5 +72,5 @@ return cache.value; | ||
} | ||
export default function computed(cb, options) { | ||
export default function compute(cb, options) { | ||
return new Computed(cb, options); | ||
} | ||
//# sourceMappingURL=computed.js.map |
@@ -1,2 +0,2 @@ | ||
import App, { computed } from './'; | ||
import App, { compute } from './'; | ||
describe('Computed', () => { | ||
@@ -6,3 +6,3 @@ test('should instantiate app with computed', () => { | ||
foo: 'bar', | ||
test: computed((foo) => (state) => state.foo + foo), | ||
test: compute((foo) => (state) => state.foo + foo), | ||
}; | ||
@@ -18,3 +18,3 @@ const app = new App({ | ||
foo: 'bar', | ||
test: computed((foo) => (state) => { | ||
test: compute((foo) => (state) => { | ||
runCount++; | ||
@@ -35,3 +35,3 @@ return state.foo + foo; | ||
foo: 'bar', | ||
test: computed((foo) => (state) => { | ||
test: compute((foo) => (state) => { | ||
runCount++; | ||
@@ -52,3 +52,3 @@ return state.foo + foo; | ||
foo: 'bar', | ||
test: computed((foo) => (state) => { | ||
test: compute((foo) => (state) => { | ||
runCount++; | ||
@@ -73,3 +73,3 @@ return state.foo + foo; | ||
foo: 'bar', | ||
test: computed((foo) => (state) => { | ||
test: compute((foo) => (state) => { | ||
runCount++; | ||
@@ -76,0 +76,0 @@ return state.foo + foo; |
@@ -1,1 +0,1 @@ | ||
export default function derived<NewValue>(cb: (state: object) => NewValue): NewValue; | ||
export default function derive<NewValue>(cb: (state: object) => NewValue): NewValue; |
@@ -0,1 +1,2 @@ | ||
import { EventType } from './'; | ||
class Derived { | ||
@@ -21,3 +22,3 @@ constructor(cb) { | ||
this.proxyStateTreeListener = proxyStateTree.addMutationListener(this.paths, (flushId) => { | ||
eventHub.emit('derived:dirty', { | ||
eventHub.emitAsync(EventType.DERIVED_DIRTY, { | ||
path, | ||
@@ -29,3 +30,3 @@ flushId, | ||
} | ||
eventHub.emit('derived', { | ||
eventHub.emitAsync(EventType.DERIVED, { | ||
path, | ||
@@ -45,5 +46,5 @@ paths: Array.from(this.paths), | ||
} | ||
export default function derived(cb) { | ||
export default function derive(cb) { | ||
return new Derived(cb); | ||
} | ||
//# sourceMappingURL=derived.js.map |
@@ -1,2 +0,2 @@ | ||
import App, { derived } from './'; | ||
import App, { derive } from './'; | ||
describe('Derived', () => { | ||
@@ -7,3 +7,3 @@ test('should instantiate app with derived state', () => { | ||
foo: 'bar', | ||
upperFoo: derived((state) => state.foo.toUpperCase()), | ||
upperFoo: derive((state) => state.foo.toUpperCase()), | ||
}, | ||
@@ -18,3 +18,3 @@ }); | ||
foo: 'bar', | ||
upperFoo: derived((state) => state.foo.toUpperCase()), | ||
upperFoo: derive((state) => state.foo.toUpperCase()), | ||
}, | ||
@@ -21,0 +21,0 @@ actions: (action) => ({ |
@@ -0,1 +1,2 @@ | ||
import { EventEmitter } from 'betsy'; | ||
import Devtools from './Devtools'; | ||
@@ -5,4 +6,4 @@ import { IValueAction, INoValueAction } from './Action'; | ||
export { default as namespaces, Namespace } from './namespaces'; | ||
export { default as derived } from './derived'; | ||
export { default as computed } from './computed'; | ||
export { default as derive } from './derived'; | ||
export { default as compute } from './computed'; | ||
declare type Configuration<State, Effects, Actions, Reactions> = { | ||
@@ -17,4 +18,21 @@ state?: State; | ||
}; | ||
declare type CacheMessage = { | ||
value: any; | ||
paths: string[]; | ||
updateCount: number; | ||
}; | ||
export declare enum EventType { | ||
DERIVED = "derived", | ||
DERIVED_DIRTY = "derived:dirty", | ||
COMPUTED = "computed", | ||
COMPUTED_DIRTY = "computed:dirty", | ||
REACTION_ADD = "reaction:add", | ||
REACTION_UPDATE = "reaction:update", | ||
REACTION_REMOVE = "reaction:remove", | ||
COMPONENT_ADD = "component:add", | ||
COMPONENT_UPDATE = "component:update", | ||
COMPONENT_REMOVE = "component:remove" | ||
} | ||
export interface Events { | ||
derived: { | ||
[EventType.DERIVED]: { | ||
path: string; | ||
@@ -25,20 +43,17 @@ paths: string[]; | ||
}; | ||
'derived:dirty': { | ||
[EventType.DERIVED_DIRTY]: { | ||
path: string; | ||
flushId: number; | ||
}; | ||
computed: { | ||
[EventType.COMPUTED]: { | ||
path: string; | ||
paths: string[]; | ||
updateCount: number; | ||
value: any; | ||
cache: CacheMessage[]; | ||
limit: number; | ||
cacheKeysCount: number; | ||
cacheKeyIndex: number; | ||
}; | ||
'computed:dirty': { | ||
[EventType.COMPUTED_DIRTY]: { | ||
path: string; | ||
flushId: number; | ||
}; | ||
'reaction:add': { | ||
[EventType.REACTION_ADD]: { | ||
path: string; | ||
@@ -48,3 +63,3 @@ statePath: string; | ||
}; | ||
'reaction:update': { | ||
[EventType.REACTION_UPDATE]: { | ||
path: string; | ||
@@ -54,3 +69,3 @@ statePath: string; | ||
}; | ||
'reaction:remove': { | ||
[EventType.REACTION_REMOVE]: { | ||
path: string; | ||
@@ -60,2 +75,20 @@ statePath: string; | ||
}; | ||
[EventType.COMPONENT_ADD]: { | ||
componentId: number; | ||
componentInstanceId: number; | ||
name: string; | ||
paths: string[]; | ||
}; | ||
[EventType.COMPONENT_UPDATE]: { | ||
componentId: number; | ||
componentInstanceId: number; | ||
name: string; | ||
paths: string[]; | ||
flushId: number; | ||
}; | ||
[EventType.COMPONENT_REMOVE]: { | ||
componentId: number; | ||
componentInstanceId: number; | ||
name: string; | ||
}; | ||
} | ||
@@ -80,3 +113,3 @@ export declare type ActionsCallback<Effects, State> = (action: TAction<State, Effects & { | ||
private proxyStateTree; | ||
private eventHub; | ||
eventHub: EventEmitter<Events>; | ||
devtools: Devtools; | ||
@@ -83,0 +116,0 @@ actions: Actions extends ActionsCallback<Effects, State> ? ReturnType<Actions> : Actions extends { |
@@ -8,4 +8,17 @@ import { ActionChain } from 'action-chain'; | ||
export { default as namespaces } from './namespaces'; | ||
export { default as derived } from './derived'; | ||
export { default as computed } from './computed'; | ||
export { default as derive } from './derived'; | ||
export { default as compute } from './computed'; | ||
export var EventType; | ||
(function (EventType) { | ||
EventType["DERIVED"] = "derived"; | ||
EventType["DERIVED_DIRTY"] = "derived:dirty"; | ||
EventType["COMPUTED"] = "computed"; | ||
EventType["COMPUTED_DIRTY"] = "computed:dirty"; | ||
EventType["REACTION_ADD"] = "reaction:add"; | ||
EventType["REACTION_UPDATE"] = "reaction:update"; | ||
EventType["REACTION_REMOVE"] = "reaction:remove"; | ||
EventType["COMPONENT_ADD"] = "component:add"; | ||
EventType["COMPONENT_UPDATE"] = "component:update"; | ||
EventType["COMPONENT_REMOVE"] = "component:remove"; | ||
})(EventType || (EventType = {})); | ||
export default class App { | ||
@@ -81,8 +94,2 @@ constructor(configuration, options = {}) { | ||
}); | ||
devtools.send({ | ||
type: 'init', | ||
data: { | ||
state: proxyStateTree.get(), | ||
}, | ||
}); | ||
actionChain.on('action:start', (data) => devtools.send({ | ||
@@ -112,30 +119,16 @@ type: 'action:start', | ||
})); | ||
eventHub.on('derived', (data) => devtools.send({ | ||
type: 'derived', | ||
data, | ||
})); | ||
eventHub.on('derived:dirty', (data) => devtools.send({ | ||
type: 'derived:dirty', | ||
data, | ||
})); | ||
eventHub.on('computed', (data) => devtools.send({ | ||
type: 'computed', | ||
data, | ||
})); | ||
eventHub.on('computed:dirty', (data) => devtools.send({ | ||
type: 'computed:dirty', | ||
data, | ||
})); | ||
eventHub.on('reaction:add', (data) => devtools.send({ | ||
type: 'reaction:add', | ||
data, | ||
})); | ||
eventHub.on('reaction:update', (data) => devtools.send({ | ||
type: 'reaction:update', | ||
data, | ||
})); | ||
eventHub.on('reaction:remove', (data) => devtools.send({ | ||
type: 'reaction:remove', | ||
data, | ||
})); | ||
for (let type in EventType) { | ||
eventHub.on(EventType[type], (data) => devtools.send({ | ||
type: EventType[type], | ||
data, | ||
})); | ||
} | ||
// This message is always the first as it is passed synchronously, all other | ||
// events are emitted async | ||
devtools.send({ | ||
type: 'init', | ||
data: { | ||
state: proxyStateTree.get(), | ||
}, | ||
}); | ||
this.devtools = devtools; | ||
@@ -142,0 +135,0 @@ } |
@@ -0,1 +1,2 @@ | ||
import { EventType } from './'; | ||
class Reaction { | ||
@@ -17,3 +18,3 @@ constructor(eventHub, proxyStateTree, path) { | ||
if (mutation.path.indexOf(this.statePath) === 0) { | ||
this.eventHub.emit('reaction:update', { | ||
this.eventHub.emitAsync(EventType.REACTION_UPDATE, { | ||
path: this.path, | ||
@@ -27,3 +28,3 @@ statePath: this.statePath, | ||
}); | ||
this.eventHub.emit('reaction:add', { | ||
this.eventHub.emitAsync(EventType.REACTION_ADD, { | ||
path: this.path, | ||
@@ -35,3 +36,3 @@ statePath: this.statePath, | ||
destroy() { | ||
this.eventHub.emit('reaction:remove', { | ||
this.eventHub.emitAsync(EventType.REACTION_REMOVE, { | ||
path: this.path, | ||
@@ -38,0 +39,0 @@ statePath: this.statePath, |
import * as React from 'react'; | ||
import App from '../'; | ||
import App, { EventType } from '../'; | ||
export { namespaces } from '../'; | ||
@@ -18,12 +18,7 @@ let nextComponentId = 0; | ||
if (this.__mutationListener) { | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:remove', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.props.app.__componentInstanceId, | ||
name: Component.name || '', | ||
}, | ||
}); | ||
} | ||
instance.eventHub.emitAsync(EventType.COMPONENT_REMOVE, { | ||
componentId, | ||
componentInstanceId: this.props.app.__componentInstanceId, | ||
name: Component.name || '', | ||
}); | ||
this.__mutationListener.dispose(); | ||
@@ -37,8 +32,14 @@ } | ||
const paths = instance.clearTrackState(trackId); | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: this.__mutationListener | ||
? 'component:update' | ||
: 'component:add', | ||
data: { | ||
if (this.__mutationListener) { | ||
this.__mutationListener.update(paths); | ||
} | ||
else { | ||
instance.eventHub.emitAsync(EventType.COMPONENT_ADD, { | ||
componentId, | ||
componentInstanceId: this.props.app.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
}); | ||
this.__mutationListener = instance.addMutationListener(paths, (flushId) => { | ||
instance.eventHub.emitAsync(EventType.COMPONENT_UPDATE, { | ||
componentId, | ||
@@ -48,33 +49,4 @@ componentInstanceId: this.props.app.__componentInstanceId, | ||
paths: Array.from(paths), | ||
}, | ||
}); | ||
} | ||
if (this.__mutationListener) { | ||
this.__mutationListener.update(paths); | ||
} | ||
else { | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:add', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.props.app.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
}, | ||
flushId, | ||
}); | ||
} | ||
this.__mutationListener = instance.addMutationListener(paths, (flushId) => { | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:update', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.props.app.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
flushId, | ||
}, | ||
}); | ||
} | ||
this.forceUpdate(); | ||
@@ -95,12 +67,7 @@ }); | ||
if (this.__mutationListener) { | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:remove', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.__componentInstanceId, | ||
name: Component.name || '', | ||
}, | ||
}); | ||
} | ||
instance.eventHub.emitAsync(EventType.COMPONENT_REMOVE, { | ||
componentId, | ||
componentInstanceId: this.__componentInstanceId, | ||
name: Component.name || '', | ||
}); | ||
this.__mutationListener.dispose(); | ||
@@ -125,26 +92,16 @@ } | ||
else { | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:add', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
}, | ||
instance.eventHub.emitAsync(EventType.COMPONENT_ADD, { | ||
componentId, | ||
componentInstanceId: this.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
}); | ||
this.__mutationListener = instance.addMutationListener(paths, (flushId) => { | ||
instance.eventHub.emitAsync(EventType.COMPONENT_UPDATE, { | ||
componentId, | ||
componentInstanceId: this.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
flushId, | ||
}); | ||
} | ||
this.__mutationListener = instance.addMutationListener(paths, (flushId) => { | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:update', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
flushId, | ||
}, | ||
}); | ||
} | ||
this.forceUpdate(); | ||
@@ -151,0 +108,0 @@ }); |
@@ -20,3 +20,3 @@ "use strict"; | ||
const mutations = this.proxyStateTree.clearMutationTracking(); | ||
this.getActionChain().emit('mutations', Object.assign({ mutations }, effects.__execution)); | ||
this.getActionChain().emitAsync('mutations', Object.assign({ mutations }, effects.__execution)); | ||
return value; | ||
@@ -23,0 +23,0 @@ }; |
@@ -22,3 +22,3 @@ import { EventEmitter } from 'betsy'; | ||
} | ||
export default function computed<Config, NewValue>(cb: (config: Config) => (state: object) => NewValue, options?: ComputedOptions): (config: Config) => NewValue; | ||
export default function compute<Config, NewValue>(cb: (config: Config) => (state: object) => NewValue, options?: ComputedOptions): (config: Config) => NewValue; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const _1 = require("./"); | ||
class Computed { | ||
@@ -41,3 +42,3 @@ constructor(cb, options = {}) { | ||
cache.proxyStateTreeListener = proxyStateTree.addMutationListener(cache.paths, (flushId) => { | ||
eventHub.emit('computed:dirty', { | ||
eventHub.emitAsync(_1.EventType.COMPUTED_DIRTY, { | ||
path, | ||
@@ -54,10 +55,11 @@ flushId, | ||
} | ||
eventHub.emit('computed', { | ||
eventHub.emitAsync(_1.EventType.COMPUTED, { | ||
path, | ||
paths: Array.from(cache.paths), | ||
updateCount: cache.updateCount, | ||
value: cache.value, | ||
limit: this.cacheLimit, | ||
cacheKeysCount: this.cacheKeys.length, | ||
cacheKeyIndex: this.cacheKeys.indexOf(config), | ||
cache: Array.from(this.cache.values()).map((cache) => ({ | ||
value: cache.value, | ||
updateCount: cache.updateCount, | ||
paths: Array.from(cache.paths), | ||
})), | ||
}); | ||
@@ -73,6 +75,6 @@ return cache.value; | ||
exports.Computed = Computed; | ||
function computed(cb, options) { | ||
function compute(cb, options) { | ||
return new Computed(cb, options); | ||
} | ||
exports.default = computed; | ||
exports.default = compute; | ||
//# sourceMappingURL=computed.js.map |
@@ -8,3 +8,3 @@ "use strict"; | ||
foo: 'bar', | ||
test: _1.computed((foo) => (state) => state.foo + foo), | ||
test: _1.compute((foo) => (state) => state.foo + foo), | ||
}; | ||
@@ -20,3 +20,3 @@ const app = new _1.default({ | ||
foo: 'bar', | ||
test: _1.computed((foo) => (state) => { | ||
test: _1.compute((foo) => (state) => { | ||
runCount++; | ||
@@ -37,3 +37,3 @@ return state.foo + foo; | ||
foo: 'bar', | ||
test: _1.computed((foo) => (state) => { | ||
test: _1.compute((foo) => (state) => { | ||
runCount++; | ||
@@ -54,3 +54,3 @@ return state.foo + foo; | ||
foo: 'bar', | ||
test: _1.computed((foo) => (state) => { | ||
test: _1.compute((foo) => (state) => { | ||
runCount++; | ||
@@ -75,3 +75,3 @@ return state.foo + foo; | ||
foo: 'bar', | ||
test: _1.computed((foo) => (state) => { | ||
test: _1.compute((foo) => (state) => { | ||
runCount++; | ||
@@ -78,0 +78,0 @@ return state.foo + foo; |
@@ -1,1 +0,1 @@ | ||
export default function derived<NewValue>(cb: (state: object) => NewValue): NewValue; | ||
export default function derive<NewValue>(cb: (state: object) => NewValue): NewValue; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const _1 = require("./"); | ||
class Derived { | ||
@@ -23,3 +24,3 @@ constructor(cb) { | ||
this.proxyStateTreeListener = proxyStateTree.addMutationListener(this.paths, (flushId) => { | ||
eventHub.emit('derived:dirty', { | ||
eventHub.emitAsync(_1.EventType.DERIVED_DIRTY, { | ||
path, | ||
@@ -31,3 +32,3 @@ flushId, | ||
} | ||
eventHub.emit('derived', { | ||
eventHub.emitAsync(_1.EventType.DERIVED, { | ||
path, | ||
@@ -47,6 +48,6 @@ paths: Array.from(this.paths), | ||
} | ||
function derived(cb) { | ||
function derive(cb) { | ||
return new Derived(cb); | ||
} | ||
exports.default = derived; | ||
exports.default = derive; | ||
//# sourceMappingURL=derived.js.map |
@@ -9,3 +9,3 @@ "use strict"; | ||
foo: 'bar', | ||
upperFoo: _1.derived((state) => state.foo.toUpperCase()), | ||
upperFoo: _1.derive((state) => state.foo.toUpperCase()), | ||
}, | ||
@@ -20,3 +20,3 @@ }); | ||
foo: 'bar', | ||
upperFoo: _1.derived((state) => state.foo.toUpperCase()), | ||
upperFoo: _1.derive((state) => state.foo.toUpperCase()), | ||
}, | ||
@@ -23,0 +23,0 @@ actions: (action) => ({ |
@@ -0,1 +1,2 @@ | ||
import { EventEmitter } from 'betsy'; | ||
import Devtools from './Devtools'; | ||
@@ -5,4 +6,4 @@ import { IValueAction, INoValueAction } from './Action'; | ||
export { default as namespaces, Namespace } from './namespaces'; | ||
export { default as derived } from './derived'; | ||
export { default as computed } from './computed'; | ||
export { default as derive } from './derived'; | ||
export { default as compute } from './computed'; | ||
declare type Configuration<State, Effects, Actions, Reactions> = { | ||
@@ -17,4 +18,21 @@ state?: State; | ||
}; | ||
declare type CacheMessage = { | ||
value: any; | ||
paths: string[]; | ||
updateCount: number; | ||
}; | ||
export declare enum EventType { | ||
DERIVED = "derived", | ||
DERIVED_DIRTY = "derived:dirty", | ||
COMPUTED = "computed", | ||
COMPUTED_DIRTY = "computed:dirty", | ||
REACTION_ADD = "reaction:add", | ||
REACTION_UPDATE = "reaction:update", | ||
REACTION_REMOVE = "reaction:remove", | ||
COMPONENT_ADD = "component:add", | ||
COMPONENT_UPDATE = "component:update", | ||
COMPONENT_REMOVE = "component:remove" | ||
} | ||
export interface Events { | ||
derived: { | ||
[EventType.DERIVED]: { | ||
path: string; | ||
@@ -25,20 +43,17 @@ paths: string[]; | ||
}; | ||
'derived:dirty': { | ||
[EventType.DERIVED_DIRTY]: { | ||
path: string; | ||
flushId: number; | ||
}; | ||
computed: { | ||
[EventType.COMPUTED]: { | ||
path: string; | ||
paths: string[]; | ||
updateCount: number; | ||
value: any; | ||
cache: CacheMessage[]; | ||
limit: number; | ||
cacheKeysCount: number; | ||
cacheKeyIndex: number; | ||
}; | ||
'computed:dirty': { | ||
[EventType.COMPUTED_DIRTY]: { | ||
path: string; | ||
flushId: number; | ||
}; | ||
'reaction:add': { | ||
[EventType.REACTION_ADD]: { | ||
path: string; | ||
@@ -48,3 +63,3 @@ statePath: string; | ||
}; | ||
'reaction:update': { | ||
[EventType.REACTION_UPDATE]: { | ||
path: string; | ||
@@ -54,3 +69,3 @@ statePath: string; | ||
}; | ||
'reaction:remove': { | ||
[EventType.REACTION_REMOVE]: { | ||
path: string; | ||
@@ -60,2 +75,20 @@ statePath: string; | ||
}; | ||
[EventType.COMPONENT_ADD]: { | ||
componentId: number; | ||
componentInstanceId: number; | ||
name: string; | ||
paths: string[]; | ||
}; | ||
[EventType.COMPONENT_UPDATE]: { | ||
componentId: number; | ||
componentInstanceId: number; | ||
name: string; | ||
paths: string[]; | ||
flushId: number; | ||
}; | ||
[EventType.COMPONENT_REMOVE]: { | ||
componentId: number; | ||
componentInstanceId: number; | ||
name: string; | ||
}; | ||
} | ||
@@ -80,3 +113,3 @@ export declare type ActionsCallback<Effects, State> = (action: TAction<State, Effects & { | ||
private proxyStateTree; | ||
private eventHub; | ||
eventHub: EventEmitter<Events>; | ||
devtools: Devtools; | ||
@@ -83,0 +116,0 @@ actions: Actions extends ActionsCallback<Effects, State> ? ReturnType<Actions> : Actions extends { |
@@ -12,5 +12,18 @@ "use strict"; | ||
var derived_1 = require("./derived"); | ||
exports.derived = derived_1.default; | ||
exports.derive = derived_1.default; | ||
var computed_1 = require("./computed"); | ||
exports.computed = computed_1.default; | ||
exports.compute = computed_1.default; | ||
var EventType; | ||
(function (EventType) { | ||
EventType["DERIVED"] = "derived"; | ||
EventType["DERIVED_DIRTY"] = "derived:dirty"; | ||
EventType["COMPUTED"] = "computed"; | ||
EventType["COMPUTED_DIRTY"] = "computed:dirty"; | ||
EventType["REACTION_ADD"] = "reaction:add"; | ||
EventType["REACTION_UPDATE"] = "reaction:update"; | ||
EventType["REACTION_REMOVE"] = "reaction:remove"; | ||
EventType["COMPONENT_ADD"] = "component:add"; | ||
EventType["COMPONENT_UPDATE"] = "component:update"; | ||
EventType["COMPONENT_REMOVE"] = "component:remove"; | ||
})(EventType = exports.EventType || (exports.EventType = {})); | ||
class App { | ||
@@ -86,8 +99,2 @@ constructor(configuration, options = {}) { | ||
}); | ||
devtools.send({ | ||
type: 'init', | ||
data: { | ||
state: proxyStateTree.get(), | ||
}, | ||
}); | ||
actionChain.on('action:start', (data) => devtools.send({ | ||
@@ -117,30 +124,16 @@ type: 'action:start', | ||
})); | ||
eventHub.on('derived', (data) => devtools.send({ | ||
type: 'derived', | ||
data, | ||
})); | ||
eventHub.on('derived:dirty', (data) => devtools.send({ | ||
type: 'derived:dirty', | ||
data, | ||
})); | ||
eventHub.on('computed', (data) => devtools.send({ | ||
type: 'computed', | ||
data, | ||
})); | ||
eventHub.on('computed:dirty', (data) => devtools.send({ | ||
type: 'computed:dirty', | ||
data, | ||
})); | ||
eventHub.on('reaction:add', (data) => devtools.send({ | ||
type: 'reaction:add', | ||
data, | ||
})); | ||
eventHub.on('reaction:update', (data) => devtools.send({ | ||
type: 'reaction:update', | ||
data, | ||
})); | ||
eventHub.on('reaction:remove', (data) => devtools.send({ | ||
type: 'reaction:remove', | ||
data, | ||
})); | ||
for (let type in EventType) { | ||
eventHub.on(EventType[type], (data) => devtools.send({ | ||
type: EventType[type], | ||
data, | ||
})); | ||
} | ||
// This message is always the first as it is passed synchronously, all other | ||
// events are emitted async | ||
devtools.send({ | ||
type: 'init', | ||
data: { | ||
state: proxyStateTree.get(), | ||
}, | ||
}); | ||
this.devtools = devtools; | ||
@@ -147,0 +140,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const _1 = require("./"); | ||
class Reaction { | ||
@@ -19,3 +20,3 @@ constructor(eventHub, proxyStateTree, path) { | ||
if (mutation.path.indexOf(this.statePath) === 0) { | ||
this.eventHub.emit('reaction:update', { | ||
this.eventHub.emitAsync(_1.EventType.REACTION_UPDATE, { | ||
path: this.path, | ||
@@ -29,3 +30,3 @@ statePath: this.statePath, | ||
}); | ||
this.eventHub.emit('reaction:add', { | ||
this.eventHub.emitAsync(_1.EventType.REACTION_ADD, { | ||
path: this.path, | ||
@@ -37,3 +38,3 @@ statePath: this.statePath, | ||
destroy() { | ||
this.eventHub.emit('reaction:remove', { | ||
this.eventHub.emitAsync(_1.EventType.REACTION_REMOVE, { | ||
path: this.path, | ||
@@ -40,0 +41,0 @@ statePath: this.statePath, |
@@ -21,12 +21,7 @@ "use strict"; | ||
if (this.__mutationListener) { | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:remove', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.props.app.__componentInstanceId, | ||
name: Component.name || '', | ||
}, | ||
}); | ||
} | ||
instance.eventHub.emitAsync(__1.EventType.COMPONENT_REMOVE, { | ||
componentId, | ||
componentInstanceId: this.props.app.__componentInstanceId, | ||
name: Component.name || '', | ||
}); | ||
this.__mutationListener.dispose(); | ||
@@ -40,8 +35,14 @@ } | ||
const paths = instance.clearTrackState(trackId); | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: this.__mutationListener | ||
? 'component:update' | ||
: 'component:add', | ||
data: { | ||
if (this.__mutationListener) { | ||
this.__mutationListener.update(paths); | ||
} | ||
else { | ||
instance.eventHub.emitAsync(__1.EventType.COMPONENT_ADD, { | ||
componentId, | ||
componentInstanceId: this.props.app.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
}); | ||
this.__mutationListener = instance.addMutationListener(paths, (flushId) => { | ||
instance.eventHub.emitAsync(__1.EventType.COMPONENT_UPDATE, { | ||
componentId, | ||
@@ -51,33 +52,4 @@ componentInstanceId: this.props.app.__componentInstanceId, | ||
paths: Array.from(paths), | ||
}, | ||
}); | ||
} | ||
if (this.__mutationListener) { | ||
this.__mutationListener.update(paths); | ||
} | ||
else { | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:add', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.props.app.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
}, | ||
flushId, | ||
}); | ||
} | ||
this.__mutationListener = instance.addMutationListener(paths, (flushId) => { | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:update', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.props.app.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
flushId, | ||
}, | ||
}); | ||
} | ||
this.forceUpdate(); | ||
@@ -98,12 +70,7 @@ }); | ||
if (this.__mutationListener) { | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:remove', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.__componentInstanceId, | ||
name: Component.name || '', | ||
}, | ||
}); | ||
} | ||
instance.eventHub.emitAsync(__1.EventType.COMPONENT_REMOVE, { | ||
componentId, | ||
componentInstanceId: this.__componentInstanceId, | ||
name: Component.name || '', | ||
}); | ||
this.__mutationListener.dispose(); | ||
@@ -128,26 +95,16 @@ } | ||
else { | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:add', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
}, | ||
instance.eventHub.emitAsync(__1.EventType.COMPONENT_ADD, { | ||
componentId, | ||
componentInstanceId: this.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
}); | ||
this.__mutationListener = instance.addMutationListener(paths, (flushId) => { | ||
instance.eventHub.emitAsync(__1.EventType.COMPONENT_UPDATE, { | ||
componentId, | ||
componentInstanceId: this.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
flushId, | ||
}); | ||
} | ||
this.__mutationListener = instance.addMutationListener(paths, (flushId) => { | ||
if (instance.devtools) { | ||
instance.devtools.send({ | ||
type: 'component:update', | ||
data: { | ||
componentId, | ||
componentInstanceId: this.__componentInstanceId, | ||
name: Component.name || '', | ||
paths: Array.from(paths), | ||
flushId, | ||
}, | ||
}); | ||
} | ||
this.forceUpdate(); | ||
@@ -154,0 +111,0 @@ }); |
{ | ||
"name": "overmind", | ||
"version": "1.0.0-1532691371168", | ||
"version": "1.0.0-1532810720851", | ||
"description": "Functional actions", | ||
@@ -41,6 +41,6 @@ "author": "Christian Alfoni <christianalfoni@gmail.com>", | ||
"@types/node": "^10.5.1", | ||
"action-chain": "1.0.0-1532691371168", | ||
"action-chain": "1.0.0-1532810720851", | ||
"is-plain-object": "^2.0.4", | ||
"betsy": "1.0.0-1532691371168", | ||
"proxy-state-tree": "1.0.0-1532691371168", | ||
"betsy": "1.0.0-1532810720851", | ||
"proxy-state-tree": "1.0.0-1532810720851", | ||
"tslib": "^1.9.3" | ||
@@ -47,0 +47,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
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
297296
2856
+ Addedaction-chain@1.0.0-1532810720851(transitive)
+ Addedbetsy@1.0.0-1532810720851(transitive)
+ Addedproxy-state-tree@1.0.0-1532810720851(transitive)
- Removedaction-chain@1.0.0-1532691371168(transitive)
- Removedbetsy@1.0.0-1532691371168(transitive)
- Removedproxy-state-tree@1.0.0-1532691371168(transitive)
Updatedbetsy@1.0.0-1532810720851