Skip to content

Commit

Permalink
call onconstruct from init options from constructor - fixes #3267
Browse files Browse the repository at this point in the history
  • Loading branch information
evs-chris committed Sep 27, 2018
1 parent b4e5cde commit ce7b07e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Ractive/construct.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ATTRIBUTE, BINDING_FLAG, DECORATOR, INTERPOLATOR, TRANSITION } from 'co
import { assign, create, hasOwn } from 'utils/object';
import { isArray, isString } from 'utils/is';
import { compute } from 'src/Ractive/prototype/compute';
import getRactiveContext from '../shared/getRactiveContext';

const registryNames = [
'adaptors',
Expand Down Expand Up @@ -50,8 +51,8 @@ export default function construct(ractive, options) {
ractive.use.apply(ractive, options.use.filter(p => p.construct));
}

// TODO don't allow `onconstruct` with `new Ractive()`, there's no need for it
hooks.construct.fire(ractive, options);
if (options.onconstruct) options.onconstruct.call(ractive, getRactiveContext(ractive), options);

// Add registries
let i = registryNames.length;
Expand Down
12 changes: 12 additions & 0 deletions tests/browser/events/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,4 +418,16 @@ export default function() {
oninit() {}
});
});

test(`instance calls onconstruct for consistency sake (#3267)`, t => {
t.expect(1);

new Ractive({
target: fixture,
template: 'sure',
onconstruct() {
t.ok(true);
}
});
});
}
2 changes: 1 addition & 1 deletion tests/browser/init/hooks/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export default function() {
const topDown = ['parent', 'child', 'grandchild'];
const bottomUp = ['grandchild', 'child', 'parent'];

testHierarchy('onconstruct', ['child', 'grandchild']);
testHierarchy('onconstruct', topDown);
testHierarchy('onconfig', topDown);
testHierarchy('oninit', topDown);
testHierarchy('onrender', topDown);
Expand Down

0 comments on commit ce7b07e

Please sign in to comment.