@@ -106,14 +106,24 @@ export const parseFunction = async (
106106 errorPaths : state . errorPaths ,
107107 } ;
108108 }
109-
110109 }
111110}
112111
113112export const parseObject = async ( current : Moss . ReturnValue ) => {
114113 const { state } = current ;
115114 const source : any = clone ( current . data ) ;
116115 const target = state . target || current . data ;
116+
117+ // Expand has precedence
118+ for ( const _key of Object . keys ( source ) ) {
119+ if ( _key [ 0 ] === '~' && _key . indexOf ( "." ) != - 1 ) {
120+ const kp = _key . slice ( 1 ) ;
121+ setValueForKeyPath ( source [ _key ] , kp , source ) ;
122+ delete source [ _key ] ;
123+ delete target [ _key ] ;
124+ }
125+ }
126+
117127 for ( const _key of Object . keys ( source ) ) {
118128 let res ;
119129 if ( ! _key ) {
@@ -133,12 +143,7 @@ export const parseObject = async (current: Moss.ReturnValue) => {
133143 if ( _key [ 0 ] === "$" ) {
134144 key = < any > ( await interpolate ( current , _key ) ) . data ;
135145 } else if ( _key [ 0 ] == "\\" ) {
136- key = key . slice ( 1 ) ;
137- } else if ( _key . indexOf ( "." ) != - 1 ) {
138- const [ first , ...kp ] = _key . split ( "." ) ;
139- key = first ;
140- val = { } ;
141- setValueForKeyPath ( source [ _key ] , kp . join ( "." ) , val ) ;
146+ key = _key . slice ( 1 ) ;
142147 } else {
143148 key = _key ;
144149 }
@@ -155,6 +160,17 @@ export const parseObject = async (current: Moss.ReturnValue) => {
155160 return current ;
156161} ;
157162
163+ export const wrapFunction = ( fn : Function , transformArgs ?: ( args : any ) => any [ ] ) => async ( current : Moss . ReturnValue , args : Moss . BranchData , setRes : any ) => {
164+ const { data } = await continueWithNewFrame ( current , args ) ;
165+ let res ;
166+ if ( transformArgs ) {
167+ res = await fn ( ...transformArgs ( data ) ) ;
168+ } else {
169+ res = await fn ( data ) ;
170+ }
171+ setRes ? await setRes ( res ) : current . data = res ;
172+ }
173+
158174export const parseArray = async (
159175 layer : Moss . ReturnValue ,
160176 input : Moss . BranchData
@@ -550,7 +566,7 @@ addFunctions({
550566 const layer = await continueWithNewFrame ( parent , args ) ;
551567 const { data } = layer ;
552568 parent . data = sum ( data , ( v : any ) => v ) ;
553- } ,
569+ }
554570} ) ;
555571
556572async function interpolate ( layer : Moss . ReturnValue , input : any ) {
0 commit comments