Skip to content

Commit

Permalink
feat(viewport): add viewport name to life cycle arguments
Browse files Browse the repository at this point in the history
Let the viewmodel be aware of which viewport is it being rendered in
  • Loading branch information
balazsmeszegeto committed Apr 1, 2017
1 parent 5c03ff8 commit 34ef2c4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/navigation-instruction.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,14 @@ export class NavigationInstruction {
* Adds a viewPort instruction.
*/
addViewPortInstruction(viewPortName: string, strategy: string, moduleId: string, component: any): any {
const config = Object.assign({}, this.lifecycleArgs[1], { currentViewPort: viewPortName });
let viewportInstruction = this.viewPortInstructions[viewPortName] = {
name: viewPortName,
strategy: strategy,
moduleId: moduleId,
component: component,
childRouter: component.childRouter,
lifecycleArgs: this.lifecycleArgs.slice()
lifecycleArgs: [].concat(this.lifecycleArgs[0], config, this.lifecycleArgs[2])
};

return viewportInstruction;
Expand Down
31 changes: 30 additions & 1 deletion test/activation.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {
CanDeactivatePreviousStep,
CanActivateNextStep
CanActivateNextStep,
ActivateNextStep
} from '../src/activation';
import {activationStrategy} from '../src/navigation-plan';
import {NavigationInstruction} from '../src/navigation-instruction';
import {createPipelineState} from './test-util';

describe('activation', () => {
Expand Down Expand Up @@ -184,4 +186,31 @@ describe('activation', () => {
expect(state.rejection).toBeTruthy();
});
});

describe('ActivateNextStep', () => {
let step;
let state;

beforeEach(() => {
step = new ActivateNextStep();
});

it('should pass current viewport name to activate', (done) => {
const instruction = new NavigationInstruction({
plan: {
"my-view-port": { strategy: activationStrategy.invokeLifecycle }
}
});

const viewModel = {
activate(params, config, instruction) {
expect(config.currentViewPort).toBe('my-view-port');
done();
}
}

instruction.addViewPortInstruction('my-view-port', 'ignored', 'ignored', { viewModel });
step.run(instruction);
});
});
});

0 comments on commit 34ef2c4

Please sign in to comment.