-
Notifications
You must be signed in to change notification settings - Fork 640
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
WIP: Improved types, Fixes #64, #56, #9 #65
Conversation
src/core/types.ts
Outdated
), | ||
type: this, | ||
isFactory: true, | ||
factoryName: this.name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really needed? Why not use this.type.name instead? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, left it as is for now, will factor out later
src/core/types.ts
Outdated
@@ -69,3 +70,8 @@ export abstract class ComplexType extends Type { | |||
return this.isValidSnapshot(value) | |||
} | |||
} | |||
|
|||
export function typecheck(type: IType, snapshot: any) { | |||
if (!type.is(snapshot)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Maybe on production build this could be removed to speedup execution, but fails with errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, see also #62
test/type-system.ts
Outdated
x: types.number, | ||
y: types.maybe(types.string), | ||
method() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Also add a computed property and a manual test for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Changes Unknown when pulling 3ad167a on improved-types into ** on master**. |
src/core/administration.ts
Outdated
@@ -163,7 +163,7 @@ export class Node { | |||
|
|||
return fail(`Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '${this.path}/${subpath}', but it lives already at '${getPath(child)}'`) | |||
} | |||
const existingNode = this.getChildNode(subpath) | |||
const existingNode = this.getChildMST(subpath) | |||
const newInstance = childFactory.create(child) | |||
|
|||
if (existingNode && existingNode.type === newInstance.factory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Should'nt be getType(newInstance) on the right side?
Changes Unknown when pulling 342b82a on improved-types into ** on master**. |
Changes Unknown when pulling bc7b2fe on improved-types into ** on master**. |
@mattiamanzati what do you think, ok to merge? Still some todo's left, but I think the current setup is good and nice enough to cut a new release, to no longer postpone all the breaking changed 🙈 |
Changes Unknown when pulling 2d88f1a on improved-types into ** on master**. |
Uh, I think that identifier should also be changed to return a constant value or to be a generic type. The reason is because the parenthesis are used on a type only if that type is generic. const Todo = t.model({ where identifier() is something like Object.assign({}, type, {isIdentifier: true}). |
Great suggestion! Will adjust identifier |
Hey, guys! |
today or tomorrow I think |
@mweststrate Cool! Thank you |
What is the plan about publish this to NPM? |
A()
toA.create()
(better typescript support, easier internal factory construction / typing)action
Type
&Factory