@@ -13,8 +13,8 @@ import {
13
13
export interface CustomTypeOptions < S , T > {
14
14
/** Friendly name */
15
15
name : string
16
- /** given a serialized value, how to turn it into the target type */
17
- fromSnapshot ( snapshot : S ) : T
16
+ /** given a serialized value and environment , how to turn it into the target type */
17
+ fromSnapshot ( snapshot : S , env ?: any ) : T
18
18
/** return the serialization of the current value */
19
19
toSnapshot ( value : T ) : S
20
20
/** if true, this is a converted value, if false, it's a snapshot */
@@ -33,8 +33,8 @@ export interface CustomTypeOptions<S, T> {
33
33
* export interface CustomTypeOptions<S, T> {
34
34
* // Friendly name
35
35
* name: string
36
- * // given a serialized value, how to turn it into the target type
37
- * fromSnapshot(snapshot: S): T
36
+ * // given a serialized value and environment , how to turn it into the target type
37
+ * fromSnapshot(snapshot: S, env: any ): T
38
38
* // return the serialization of the current value
39
39
* toSnapshot(value: T): S
40
40
* // if true, this is a converted value, if false, it's a snapshot
@@ -116,7 +116,7 @@ export class CustomType<S, T> extends SimpleType<S | T, S, T> {
116
116
) : this[ "N" ] {
117
117
const valueToStore : T = this . options . isTargetType ( initialValue )
118
118
? ( initialValue as T )
119
- : this . options . fromSnapshot ( initialValue as S )
119
+ : this . options . fromSnapshot ( initialValue as S , parent && parent . root . environment )
120
120
return createScalarNode ( this , parent , subpath , environment , valueToStore )
121
121
}
122
122
@@ -132,7 +132,9 @@ export class CustomType<S, T> extends SimpleType<S | T, S, T> {
132
132
return current
133
133
}
134
134
}
135
- const valueToStore : T = isSnapshot ? this . options . fromSnapshot ( value as S ) : ( value as T )
135
+ const valueToStore : T = isSnapshot
136
+ ? this . options . fromSnapshot ( value as S , parent . root . environment )
137
+ : ( value as T )
136
138
const newNode = this . instantiate ( parent , subpath , undefined , valueToStore )
137
139
current . die ( ) // noop if detaching
138
140
return newNode
0 commit comments