Skip to content

Commit

Permalink
feat: merge passing context by default
Browse files Browse the repository at this point in the history
Merge pull request #204 from nightire/context-merging

BREAKING CHANGE: context is now merged instead of replaced
  • Loading branch information
NullVoxPopuli authored Jan 9, 2022
2 parents c75bc1c + 85d4b91 commit 643a8c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class ComponentManager {
machine = machine.withConfig(named.config as any);
}

let context = {};
let context = { ...machine.context };

if ('context' in named) {
Object.assign(context, named.context);
Expand Down
21 changes: 21 additions & 0 deletions testing/ember-app/tests/tests/integration/usage-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,27 @@ module('Usage', function (hooks) {
assert.strictEqual(context.numCalled, 13);
});

test('merging passed context by default', async function (assert) {
let toggle = createMachine({
initial: 'inactive',
context: { foo: 'foo' },
states: {
inactive: { on: { TOGGLE: 'active' } },
active: { on: { TOGGLE: 'inactive' } },
},
});

this.setProperties({ toggle, context: { bar: 'bar' } });

await render(hbs`
<this.toggle @context={{this.context}} as |state send|>
{{state.context.foo}}, {{state.context.bar}}
</this.toggle>
`);

assert.dom().containsText('foo, bar');
});

test('can pass initial state', async function (assert) {
let toggle = createMachine({
initial: 'inactive',
Expand Down

0 comments on commit 643a8c6

Please sign in to comment.