@cerebral/fluent
Advanced tools
Comparing version 1.0.0-1518723490701 to 1.0.0-1518821845306
@@ -5,8 +5,8 @@ export declare type ComputedValue<T> = { | ||
export declare class ComputedClass<T> { | ||
callback: (state: any) => T; | ||
callback: (state: any, root: any) => T; | ||
instance: ComputedValue<T>; | ||
getState: () => any; | ||
constructor(callback: (state: any) => T); | ||
constructor(callback: (state: any, root: any) => T); | ||
get(): T; | ||
} | ||
export declare function Computed<T>(callback: (state: any) => T): ComputedClass<T>; | ||
export declare function Computed<T>(callback: (state: any, root: any) => T): ComputedClass<T>; |
@@ -7,3 +7,3 @@ import { computed as mobxComputed } from 'mobx'; | ||
get() { | ||
this.instance = this.instance || mobxComputed(() => this.callback(this.getState())); | ||
this.instance = this.instance || mobxComputed(() => this.callback(this.getState().state, this.getState().root)); | ||
return this.instance.get(); | ||
@@ -10,0 +10,0 @@ } |
@@ -107,4 +107,4 @@ /* eslint-env mocha */ | ||
let hasUpdated = 0; | ||
const computed = function getter(state) { | ||
return state.foo.toUpperCase(); | ||
const computed = function getter(state, root) { | ||
return state.foo.toUpperCase() + root.foo; | ||
}; | ||
@@ -125,3 +125,3 @@ const rootModule = Module({ | ||
}); | ||
assert.equal(controller.state.test.get(), 'BAR'); | ||
assert.equal(controller.state.test.get(), 'BARbar'); | ||
controller.signals.test(); | ||
@@ -128,0 +128,0 @@ assert.equal(hasUpdated, 2); |
@@ -318,3 +318,3 @@ import { extractModuleProp, isObject, BaseModel } from 'cerebral/internal'; | ||
if (extension[key] instanceof ComputedClass) { | ||
extension[key].getState = () => extended; | ||
extension[key].getState = () => ({ state: extended, root: this.state }); | ||
root[key] = extension[key]; | ||
@@ -321,0 +321,0 @@ } |
{ | ||
"name": "@cerebral/fluent", | ||
"version": "1.0.0-1518723490701", | ||
"version": "1.0.0-1518821845306", | ||
"description": "Makes Cerebral typescript friendly", | ||
@@ -27,3 +27,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"cerebral": "^4.2.0-1518723490701", | ||
"cerebral": "^4.2.0-1518821845307", | ||
"mobx": "^3.4.1" | ||
@@ -30,0 +30,0 @@ }, |
60562