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

[CustomType] Add 'environment' as second argument for options.fromSnapshot #1410

Merged
merged 3 commits into from
Oct 31, 2019

Conversation

k-g-a
Copy link
Member

@k-g-a k-g-a commented Oct 28, 2019

It seems like a common case to modify custom-type's value using environment, i.e. for mocking dates in tests or using i18n.
This PR makes it possible via passing current tree's environment as second argument to the fromSnapshot method.
Initially I tried to pass parent - but it's ObjectNode which is non-conventional for MST (we ususally do not pass bare nodes to userland). My second attempt was to pass parent.storedValue (which is IAnyStateTreeNode and is more common), but it's undefined by the time we call fromSnapshot and we can not call .value either as we are actually in the middle of the observable node creation.
So the only valid option left is to pass at least the environment itself.

Typedoc edited.
Test added.

Copy link
Member

@mweststrate mweststrate left a comment

Choose a reason for hiding this comment

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

Needs minor change to not break the public API it seems. Beyond that LGTM 👏, so feel free to merge.

packages/mobx-state-tree/src/types/utility-types/custom.ts Outdated Show resolved Hide resolved
@mweststrate mweststrate merged commit ab92f00 into master Oct 31, 2019
@mweststrate
Copy link
Member

Released as 3.16.0. Terribly sorry for the late follow up! Do ping me next time if this is annoying!

@Bnaya Bnaya deleted the custom-type-env branch June 27, 2020 16:52
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