2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -245,14 +245,8 @@ export class Node {
245
245
* @returns The context object or an empty object if there is discovered context
246
246
*/
247
247
public getAllContext ( defaults ?: object ) : any {
248
- if ( typeof defaults === 'undefined' ) {
249
- defaults = { } ;
250
- }
251
-
252
- if ( this . scope === undefined ) { return defaults ; }
253
-
254
- const value = { ...this . _context , ...defaults } ;
255
- return this . scope && this . scope . node . getAllContext ( value ) ;
248
+ return this . scopes . reverse ( )
249
+ . reduce ( ( a , s ) => ( { ...( s . node . _context ) , ...a } ) , { ...defaults } ) ;
256
250
}
257
251
258
252
/**
Original file line number Diff line number Diff line change @@ -150,6 +150,23 @@ test('construct.getContext(key) throws if context is not defined', () => {
150
150
} ) . toThrowError ( `No context value present for ${ key } key` ) ;
151
151
} ) ;
152
152
153
+ test ( 'construct.getAllContext can be used to read the full context of a root node' , ( ) => {
154
+ // GIVEN
155
+ const context = {
156
+ ctx1 : 12 ,
157
+ ctx2 : 'hello' ,
158
+ } ;
159
+
160
+ // WHEN
161
+ const t = new Root ( ) ;
162
+ for ( const [ k , v ] of Object . entries ( context ) ) {
163
+ t . node . setContext ( k , v ) ;
164
+ }
165
+
166
+ // THEN
167
+ expect ( t . node . getAllContext ( ) ) . toStrictEqual ( context ) ;
168
+ } ) ;
169
+
153
170
test ( 'construct.getAllContext can be used to read the full context of a node' , ( ) => {
154
171
// GIVEN
155
172
const context = {
0 commit comments