diff --git a/notes.md b/notes.md index eb5af058c..ced01fb0b 100644 --- a/notes.md +++ b/notes.md @@ -91,10 +91,10 @@ - [ ] post 6.0 - [ ] make cheatsheet - [ ] support mobx-utils `computedFn` as annotation? - - [ ] merge https://github.com/mobxjs/mobx/pull/2389 - - [ ] set up discussions + - [x] merge https://github.com/mobxjs/mobx/pull/2389 + - [x] set up discussions - [ ] use autObservable options for codemod (if no superclass)? - - [ ] add a solution for keepAlive computeds like https://github.com/mobxjs/mobx/issues/2309#issuecomment-598707584 + - [x] add a solution for keepAlive computeds like https://github.com/mobxjs/mobx/issues/2309#issuecomment-598707584 - [ ] set up continous delivery - [ ] support chrome formatter https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html also in Immer? diff --git a/package.json b/package.json index dfa9ef0d5..59f0b2bc0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mobx", - "version": "6.0.0-rc.1", + "version": "6.0.0-rc.3", "description": "Simple, scalable state management.", "main": "dist/index.js", "module": "dist/mobx.esm.js", diff --git a/packages/mobx-undecorate/package.json b/packages/mobx-undecorate/package.json index 38829d381..bb8f9cba9 100644 --- a/packages/mobx-undecorate/package.json +++ b/packages/mobx-undecorate/package.json @@ -1,6 +1,6 @@ { "name": "mobx-undecorate", - "version": "0.0.5", + "version": "0.0.6", "description": "Migrate MobX 4/5 to MobX 6", "bin": "cli.js", "scripts": { diff --git a/src/api/computed.ts b/src/api/computed.ts index 1ab98fceb..52fc147a4 100644 --- a/src/api/computed.ts +++ b/src/api/computed.ts @@ -8,7 +8,8 @@ import { isPlainObject, isFunction, assign, - die + die, + IComputedValue } from "../internal" export const COMPUTED = "computed" @@ -18,7 +19,7 @@ export interface IComputedFactory extends Annotation, PropertyDecorator { // @computed(opts) (options: IComputedValueOptions): Annotation & PropertyDecorator // computed(fn, opts) - (func: () => T, options?: IComputedValueOptions): ComputedValue + (func: () => T, options?: IComputedValueOptions): IComputedValue struct: Annotation & PropertyDecorator } diff --git a/src/core/computedvalue.ts b/src/core/computedvalue.ts index 1bf5dffbf..4e2220f7a 100644 --- a/src/core/computedvalue.ts +++ b/src/core/computedvalue.ts @@ -94,7 +94,7 @@ export class ComputedValue implements IObservable, IComputedValue, IDeriva triggeredBy_?: string isComputing_: boolean = false // to check for cycles isRunningSetter_: boolean = false - derivation_: () => T + derivation: () => T setter_?: (value: T) => void isTracing_: TraceMode = TraceMode.NONE scope_: Object | undefined @@ -116,7 +116,7 @@ export class ComputedValue implements IObservable, IComputedValue, IDeriva */ constructor(options: IComputedValueOptions) { if (!options.get) die(31) - this.derivation_ = options.get! + this.derivation = options.get! this.name_ = options.name || "ComputedValue@" + getNextId() if (options.set) this.setter_ = createAction(this.name_ + "-setter", options.set) as any this.equals_ = @@ -153,7 +153,7 @@ export class ComputedValue implements IObservable, IComputedValue, IDeriva * Will evaluate its computation first if needed. */ public get(): T { - if (this.isComputing_) die(32, this.name_, this.derivation_) + if (this.isComputing_) die(32, this.name_, this.derivation) if ( globalState.inBatch === 0 && // !globalState.trackingDerivatpion && @@ -229,13 +229,13 @@ export class ComputedValue implements IObservable, IComputedValue, IDeriva const prev = allowStateChangesStart(false) let res: T | CaughtException if (track) { - res = trackDerivedFunction(this, this.derivation_, this.scope_) + res = trackDerivedFunction(this, this.derivation, this.scope_) } else { if (globalState.disableErrorBoundaries === true) { - res = this.derivation_.call(this.scope_) + res = this.derivation.call(this.scope_) } else { try { - res = this.derivation_.call(this.scope_) + res = this.derivation.call(this.scope_) } catch (e) { res = new CaughtException(e) } @@ -294,7 +294,7 @@ export class ComputedValue implements IObservable, IComputedValue, IDeriva } toString() { - return `${this.name_}[${this.derivation_.toString()}]` + return `${this.name_}[${this.derivation.toString()}]` } valueOf(): T { diff --git a/src/core/observable.ts b/src/core/observable.ts index 60696c27d..047cf6cab 100644 --- a/src/core/observable.ts +++ b/src/core/observable.ts @@ -252,7 +252,7 @@ You are entering this break point because derivation '${derivation.name_}' is be Just follow the stacktrace you should now see in the devtools to see precisely what piece of your code is causing this update The stackframe you are looking for is at least ~6-8 stack-frames up. -${derivation instanceof ComputedValue ? derivation.derivation_.toString().replace(/[*]\//g, "/") : ""} +${derivation instanceof ComputedValue ? derivation.derivation.toString().replace(/[*]\//g, "/") : ""} The dependencies for this derivation are: diff --git a/src/mobx.ts b/src/mobx.ts index d7083e19b..fc4aa9644 100644 --- a/src/mobx.ts +++ b/src/mobx.ts @@ -53,6 +53,8 @@ export { IObservableArray, IArrayWillChange, IArrayWillSplice, + IArraySplice, + IArrayUpdate, IArrayDidChange, isObservableArray, IKeyValueMap, diff --git a/src/types/observablearray.ts b/src/types/observablearray.ts index 420b03126..2a0a1d810 100644 --- a/src/types/observablearray.ts +++ b/src/types/observablearray.ts @@ -52,13 +52,13 @@ interface IArrayBaseChange { export type IArrayDidChange = IArrayUpdate | IArraySplice -interface IArrayUpdate extends IArrayBaseChange { +export interface IArrayUpdate extends IArrayBaseChange { type: "update" newValue: T oldValue: T } -interface IArraySplice extends IArrayBaseChange { +export interface IArraySplice extends IArrayBaseChange { type: "splice" added: T[] addedCount: number