Skip to content

Commit

Permalink
fix(core): merge $ like magick properties
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Apr 26, 2021
1 parent 8e62d3f commit 03a3244
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
12 changes: 10 additions & 2 deletions packages/core/lib/session/contextualize.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion packages/core/src/session/contextualize.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ module.exports = (args) ->
else if is_object_literal arg
for k, v of arg
if k is '$'
mutate new_action, v
# mutate new_action, v
for kk, vv of v
if ['config', 'metadata'].includes kk
new_action[kk] = {...new_action[kk], ...vv}
else
new_action[kk] = vv
else if k[0] is '$'
if k is '$$'
mutate new_action.metadata, v
Expand Down
45 changes: 44 additions & 1 deletion packages/core/test/session/contextualize.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,50 @@ describe 'session.contextualize', ->
]
.should.eql expect

it 'metadata as $$ object', ->
it '$ merge config in first level', ->
a_config_1 = { a_key_1: '1', a_key_overwritten: { a_key: 'overwrite 1'}}
a_config_2 = { a_key_2: '2', a_key_overwritten: { a_key: 'overwrite 2'}}
contextualize [
$: config: a_config_1
,
$: config: a_config_2
]
.config.should.eql
a_key_1: '1'
a_key_overwritten: a_key: 'overwrite 2'
a_key_2: '2'

it '$ merge metadata in first level', ->
a_metadata_1 = { a_key_1: '1', a_key_overwritten: { a_key: 'overwrite 1'}}
a_metadata_2 = { a_key_2: '2', a_key_overwritten: { a_key: 'overwrite 2'}}
contextualize [
$: metadata: a_metadata_1
,
$: metadata: a_metadata_2
]
.metadata.should.eql
a_key_1: '1'
a_key_overwritten: a_key: 'overwrite 2'
a_key_2: '2'

it '$ keys in first level unless config or metadata', ->
an_arg_1 = { a_key_1: '1', a_key_overwritten: { a_key: 'overwrite 1'}}
an_arg_2 = { a_key_2: '2', a_key_overwritten: { a_key: 'overwrite 2'}}
result = contextualize [
$: an_arg_1
,
$: an_arg_2
]
{
a_key_1: result.a_key_1
a_key_overwritten: result.a_key_overwritten
a_key_2: result.a_key_2
}.should.eql
a_key_1: '1'
a_key_overwritten: a_key: 'overwrite 2'
a_key_2: '2'

it '$$ interpreted as metadata', ->
expect =
metadata: a: '1', b: '2'
config: b: ''
Expand Down

0 comments on commit 03a3244

Please sign in to comment.