Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC annotations + subclassing rework #2641

Merged
merged 39 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
26b4f0e
wip
urugator Nov 24, 2020
32ad8f5
fix unused vars
urugator Nov 25, 2020
3bab5ad
fix comment
urugator Nov 25, 2020
5261dd6
Merge branch 'main' into fix-2593
urugator Nov 25, 2020
8044d5c
Merge branch 'main' into fix-2593
urugator Nov 25, 2020
3bb2a63
revert enumerability changes
urugator Dec 7, 2020
2a088cb
wip
urugator Dec 12, 2020
8df20fa
wip
urugator Dec 13, 2020
6490d33
wip
urugator Dec 14, 2020
ccfbcb3
wip
urugator Dec 15, 2020
e5cc9d2
wip
urugator Dec 16, 2020
0a96a03
wip
urugator Dec 16, 2020
79a43c2
wip
urugator Dec 16, 2020
9abcae3
wip
urugator Dec 17, 2020
6a6ebf6
wip
urugator Dec 17, 2020
f6700ec
wip
urugator Dec 18, 2020
2eaeeb8
wip
urugator Dec 19, 2020
6776820
wip
urugator Dec 20, 2020
277c2c6
wip
urugator Dec 20, 2020
cf38187
wip
urugator Dec 21, 2020
f67e12f
wip
urugator Dec 21, 2020
84fa3ae
wip
urugator Dec 29, 2020
408bf11
comments
urugator Dec 29, 2020
070fa3c
processing comments
urugator Jan 12, 2021
a04e977
processing comments
urugator Jan 18, 2021
cfa6540
descriptor cache
urugator Jan 19, 2021
1160bf8
...
urugator Jan 19, 2021
44ea51d
don't annotate proto on action.bound
urugator Jan 19, 2021
5550d51
optimize makeAutoObservable, fix symbolic action name, fix inferred a…
urugator Jan 19, 2021
4abf263
cleanup, defineProperty tests
urugator Jan 20, 2021
14656dd
fix comment
urugator Jan 21, 2021
b3fd353
fix comment
urugator Jan 21, 2021
c7f9102
extendObservable includes non-enumerable, optimize makeAutoObservable
urugator Jan 22, 2021
6782d25
little tweak
urugator Jan 22, 2021
96de304
fix imports, fix plain object detection
urugator Jan 23, 2021
9d31b92
docs
urugator Jan 26, 2021
6ee6637
docs
urugator Jan 26, 2021
62ba4a9
changeset
urugator Jan 26, 2021
8cb03b5
Merge branch 'main' into fix-2593
urugator Jan 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 10 additions & 28 deletions packages/mobx/src/api/makeObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,42 +62,24 @@ export function makeAutoObservable<T extends object, AdditionalKeys extends Prop
adm.make_(key, target[inferredAnnotationsSymbol][key])
}
} else {
const keys = new Set(collectAllKeys(target))
keys.forEach(key => {
if (key === "constructor" || key === $mobx) return
const ignoreKeys = { [$mobx]: 1, constructor: 1 }
mweststrate marked this conversation as resolved.
Show resolved Hide resolved
const make = key => {
if (ignoreKeys[key]) return
ignoreKeys[key] = 1
adm.make_(
key,
// must pass "undefined" for { key: undefined }
!overrides ? true : key in overrides ? overrides[key] : true
)
})
}
let current = target
while (current && current !== objectPrototype) {
ownKeys(current).forEach(make)
current = Object.getPrototypeOf(current)
}
}
} finally {
endBatch()
}
return target
}

/*
TODO check if faster
function collectAllKeys(object) {
const keys = {}
let current = object
const collect = key => (keys[key] = true)
while (current && current !== objectPrototype) {
Object.getOwnPropertyNames(current).forEach(collect)
Object.getOwnPropertySymbols(current).forEach(collect)
current = Object.getPrototypeOf(current)
}
return keys
}
*/

function collectAllKeys(object, keys: Array<PropertyKey> = []): PropertyKey[] {
keys.push(...ownKeys(object))
const proto = Object.getPrototypeOf(object)
if (proto !== objectPrototype) {
collectAllKeys(proto, keys)
}
return keys
}
2 changes: 1 addition & 1 deletion packages/mobx/src/types/actionannotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function createActionDescriptor(
}
return {
value: createAction(
annotation.options_?.name ?? key,
annotation.options_?.name ?? key.toString(),
value,
annotation.options_?.autoAction ?? false
),
Expand Down
2 changes: 1 addition & 1 deletion packages/mobx/src/types/observableobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export class ObservableObjectAdministration

inferAnnotation_(key: PropertyKey): Annotation | false {
// Inherited is fine - annotation cannot differ in subclass
let annotation = this[inferredAnnotationsSymbol]?.[key]
let annotation = this.target_[inferredAnnotationsSymbol]?.[key]
if (annotation) return annotation

let current = this.target_
Expand Down