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

feat: constant and maybe types #36

Merged

Conversation

mattiamanzati
Copy link
Contributor

Builds on top of #35

@mattiamanzati mattiamanzati mentioned this pull request Jan 18, 2017
27 tasks
@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 87.879% when pulling f5d8d94 on feature/constant-and-maybe-types into 229e8d0 on feature/with-default-type.

}

describe(){
return this.value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return this.name? (stringified)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done to make typescript-like describes. TypeScript itself shows "a" | "b" | "c", so maybe it should be JSON.stringify(this.value)

}

is(value) {
return value === this.value && super.is(value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does the super.is add?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the isPrimitive check, we can remove the extends Primitive if you want

}

export function createConstantFactory(value: any): any {
invariant(isPrimitive(value), 'Constant types can be built only on top of primitives')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future work could be to support (plain) complex types and deep Freeze?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I inteded to do it in a separate type named "forzen" or "serializable", the problem with complex object is if the equality check should be done on reference or deep equals.

import {isFactory, IFactory} from "../core/factories"

export function createMaybeFactory(type: IFactory<any, any>): IFactory<any, any>{
return createDefaultValueFactory(createUnionFactory(createConstantFactory(null), type), null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Singleton for null factory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 87.761% when pulling 98afa61 on feature/constant-and-maybe-types into 229e8d0 on feature/with-default-type.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 87.761% when pulling 5e2d5d0 on feature/constant-and-maybe-types into 229e8d0 on feature/with-default-type.

@mweststrate
Copy link
Member

Great!

@mweststrate mweststrate merged commit 590a3b5 into feature/with-default-type Feb 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants