Skip to content

Commit

Permalink
Small fixes based on mobx-utils migration
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Aug 21, 2020
1 parent 5536533 commit 289e2bc
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 17 deletions.
6 changes: 3 additions & 3 deletions notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/mobx-undecorate/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
5 changes: 3 additions & 2 deletions src/api/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
isPlainObject,
isFunction,
assign,
die
die,
IComputedValue
} from "../internal"

export const COMPUTED = "computed"
Expand All @@ -18,7 +19,7 @@ export interface IComputedFactory extends Annotation, PropertyDecorator {
// @computed(opts)
<T>(options: IComputedValueOptions<T>): Annotation & PropertyDecorator
// computed(fn, opts)
<T>(func: () => T, options?: IComputedValueOptions<T>): ComputedValue<T>
<T>(func: () => T, options?: IComputedValueOptions<T>): IComputedValue<T>

struct: Annotation & PropertyDecorator
}
Expand Down
14 changes: 7 additions & 7 deletions src/core/computedvalue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class ComputedValue<T> implements IObservable, IComputedValue<T>, 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
Expand All @@ -116,7 +116,7 @@ export class ComputedValue<T> implements IObservable, IComputedValue<T>, IDeriva
*/
constructor(options: IComputedValueOptions<T>) {
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_ =
Expand Down Expand Up @@ -153,7 +153,7 @@ export class ComputedValue<T> implements IObservable, IComputedValue<T>, 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 &&
Expand Down Expand Up @@ -229,13 +229,13 @@ export class ComputedValue<T> implements IObservable, IComputedValue<T>, 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)
}
Expand Down Expand Up @@ -294,7 +294,7 @@ export class ComputedValue<T> implements IObservable, IComputedValue<T>, IDeriva
}

toString() {
return `${this.name_}[${this.derivation_.toString()}]`
return `${this.name_}[${this.derivation.toString()}]`
}

valueOf(): T {
Expand Down
2 changes: 1 addition & 1 deletion src/core/observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions src/mobx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export {
IObservableArray,
IArrayWillChange,
IArrayWillSplice,
IArraySplice,
IArrayUpdate,
IArrayDidChange,
isObservableArray,
IKeyValueMap,
Expand Down
4 changes: 2 additions & 2 deletions src/types/observablearray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ interface IArrayBaseChange<T> {

export type IArrayDidChange<T = any> = IArrayUpdate<T> | IArraySplice<T>

interface IArrayUpdate<T = any> extends IArrayBaseChange<T> {
export interface IArrayUpdate<T = any> extends IArrayBaseChange<T> {
type: "update"
newValue: T
oldValue: T
}

interface IArraySplice<T = any> extends IArrayBaseChange<T> {
export interface IArraySplice<T = any> extends IArrayBaseChange<T> {
type: "splice"
added: T[]
addedCount: number
Expand Down

0 comments on commit 289e2bc

Please sign in to comment.