Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose root as a public property #1023

Merged
merged 1 commit into from
Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/generators/dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export default function dom(
const constructorBody = deindent`
${options.dev && `this._debugName = '${debugName}';`}
${options.dev && !generator.customElement &&
`if (!options || (!options.target && !options._root)) throw new Error("'target' is a required option");`}
`if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option");`}
@init(this, options);
${generator.usesRefs && `this.refs = {};`}
this._state = @assign(${initialState.join(', ')});
Expand Down Expand Up @@ -239,13 +239,13 @@ export default function dom(
${templateProperties.oncreate && `var _oncreate = %oncreate.bind(this);`}

${(templateProperties.oncreate || generator.hasComponents || generator.hasComplexBindings || generator.hasIntroTransitions) && deindent`
if (!options._root) {
if (!options.root) {
this._oncreate = [${templateProperties.oncreate && `_oncreate`}];
${(generator.hasComponents || generator.hasComplexBindings) && `this._beforecreate = [];`}
${(generator.hasComponents || generator.hasIntroTransitions) && `this._aftercreate = [];`}
} ${templateProperties.oncreate && deindent`
else {
this._root._oncreate.push(_oncreate);
this.root._oncreate.push(_oncreate);
}
`}
`}
Expand Down
4 changes: 2 additions & 2 deletions src/generators/nodes/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class Component extends Node {

const name = this.var;

const componentInitProperties = [`_root: #component._root`];
const componentInitProperties = [`root: #component.root`];

if (this.children.length > 0) {
const slots = Array.from(this._slots).map(name => `${name}: @createFragment()`);
Expand Down Expand Up @@ -217,7 +217,7 @@ export default class Component extends Node {
`);

beforecreate = deindent`
#component._root._beforecreate.push(function() {
#component.root._beforecreate.push(function() {
var state = #component.get(), childState = ${name}.get(), newState = {};
if (!childState) return;
${setParentFromChildOnInit}
Expand Down
6 changes: 3 additions & 3 deletions src/generators/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ export default class Element extends Node {
this.generator.hasComplexBindings = true;

block.builders.hydrate.addLine(
`if (!(${allInitialStateIsDefined})) #component._root._beforecreate.push(${handler});`
`if (!(${allInitialStateIsDefined})) #component.root._beforecreate.push(${handler});`
);
}
});
Expand Down Expand Up @@ -556,7 +556,7 @@ export default class Element extends Node {
const fn = `%transitions-${intro.name}`;

block.builders.intro.addBlock(deindent`
#component._root._aftercreate.push(function() {
#component.root._aftercreate.push(function() {
if (!${name}) ${name} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, true, null);
${name}.run(true, function() {
#component.fire("intro.end", { node: ${this.var} });
Expand Down Expand Up @@ -593,7 +593,7 @@ export default class Element extends Node {
}

block.builders.intro.addBlock(deindent`
#component._root._aftercreate.push(function() {
#component.root._aftercreate.push(function() {
${introName} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, true, null);
${introName}.run(true, function() {
#component.fire("intro.end", { node: ${this.var} });
Expand Down
16 changes: 8 additions & 8 deletions src/shared/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ export function get(key) {
export function init(component, options) {
component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._root = options._root || component;
component._bind = options._bind;

component.options = options;
component.store = component._root.options.store;
component.root = options.root || component;
component.store = component.root.options.store;
}

export function observe(key, callback, options) {
Expand Down Expand Up @@ -136,12 +136,12 @@ export function onDev(eventName, handler) {

export function set(newState) {
this._set(assign({}, newState));
if (this._root._lock) return;
this._root._lock = true;
callAll(this._root._beforecreate);
callAll(this._root._oncreate);
callAll(this._root._aftercreate);
this._root._lock = false;
if (this.root._lock) return;
this.root._lock = true;
callAll(this.root._beforecreate);
callAll(this.root._oncreate);
callAll(this.root._aftercreate);
this.root._lock = false;
}

export function _set(newState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ function get(key) {
function init(component, options) {
component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._root = options._root || component;
component._bind = options._bind;

component.options = options;
component.store = component._root.options.store;
component.root = options.root || component;
component.store = component.root.options.store;
}

function observe(key, callback, options) {
Expand Down Expand Up @@ -137,12 +137,12 @@ function on(eventName, handler) {

function set(newState) {
this._set(assign({}, newState));
if (this._root._lock) return;
this._root._lock = true;
callAll(this._root._beforecreate);
callAll(this._root._oncreate);
callAll(this._root._aftercreate);
this._root._lock = false;
if (this.root._lock) return;
this.root._lock = true;
callAll(this.root._beforecreate);
callAll(this.root._oncreate);
callAll(this.root._aftercreate);
this.root._lock = false;
}

function _set(newState) {
Expand Down
20 changes: 10 additions & 10 deletions test/js/samples/component-static/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ function get(key) {
function init(component, options) {
component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._root = options._root || component;
component._bind = options._bind;

component.options = options;
component.store = component._root.options.store;
component.root = options.root || component;
component.store = component.root.options.store;
}

function observe(key, callback, options) {
Expand Down Expand Up @@ -113,12 +113,12 @@ function on(eventName, handler) {

function set(newState) {
this._set(assign({}, newState));
if (this._root._lock) return;
this._root._lock = true;
callAll(this._root._beforecreate);
callAll(this._root._oncreate);
callAll(this._root._aftercreate);
this._root._lock = false;
if (this.root._lock) return;
this.root._lock = true;
callAll(this.root._beforecreate);
callAll(this.root._oncreate);
callAll(this.root._aftercreate);
this.root._lock = false;
}

function _set(newState) {
Expand Down Expand Up @@ -174,7 +174,7 @@ var Nested = window.Nested;
function create_main_fragment(state, component) {

var nested = new Nested({
_root: component._root,
root: component.root,
data: { foo: "bar" }
});

Expand Down Expand Up @@ -203,7 +203,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);

if (!options._root) {
if (!options.root) {
this._oncreate = [];
this._beforecreate = [];
this._aftercreate = [];
Expand Down
4 changes: 2 additions & 2 deletions test/js/samples/component-static/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var Nested = window.Nested;
function create_main_fragment(state, component) {

var nested = new Nested({
_root: component._root,
root: component.root,
data: { foo: "bar" }
});

Expand Down Expand Up @@ -35,7 +35,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);

if (!options._root) {
if (!options.root) {
this._oncreate = [];
this._beforecreate = [];
this._aftercreate = [];
Expand Down
16 changes: 8 additions & 8 deletions test/js/samples/computed-collapsed-if/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ function get(key) {
function init(component, options) {
component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._root = options._root || component;
component._bind = options._bind;

component.options = options;
component.store = component._root.options.store;
component.root = options.root || component;
component.store = component.root.options.store;
}

function observe(key, callback, options) {
Expand Down Expand Up @@ -113,12 +113,12 @@ function on(eventName, handler) {

function set(newState) {
this._set(assign({}, newState));
if (this._root._lock) return;
this._root._lock = true;
callAll(this._root._beforecreate);
callAll(this._root._oncreate);
callAll(this._root._aftercreate);
this._root._lock = false;
if (this.root._lock) return;
this.root._lock = true;
callAll(this.root._beforecreate);
callAll(this.root._oncreate);
callAll(this.root._aftercreate);
this.root._lock = false;
}

function _set(newState) {
Expand Down
16 changes: 8 additions & 8 deletions test/js/samples/css-media-query/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ function get(key) {
function init(component, options) {
component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._root = options._root || component;
component._bind = options._bind;

component.options = options;
component.store = component._root.options.store;
component.root = options.root || component;
component.store = component.root.options.store;
}

function observe(key, callback, options) {
Expand Down Expand Up @@ -133,12 +133,12 @@ function on(eventName, handler) {

function set(newState) {
this._set(assign({}, newState));
if (this._root._lock) return;
this._root._lock = true;
callAll(this._root._beforecreate);
callAll(this._root._oncreate);
callAll(this._root._aftercreate);
this._root._lock = false;
if (this.root._lock) return;
this.root._lock = true;
callAll(this.root._beforecreate);
callAll(this.root._oncreate);
callAll(this.root._aftercreate);
this.root._lock = false;
}

function _set(newState) {
Expand Down
16 changes: 8 additions & 8 deletions test/js/samples/css-shadow-dom-keyframes/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ function get(key) {
function init(component, options) {
component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._root = options._root || component;
component._bind = options._bind;

component.options = options;
component.store = component._root.options.store;
component.root = options.root || component;
component.store = component.root.options.store;
}

function observe(key, callback, options) {
Expand Down Expand Up @@ -125,12 +125,12 @@ function on(eventName, handler) {

function set(newState) {
this._set(assign({}, newState));
if (this._root._lock) return;
this._root._lock = true;
callAll(this._root._beforecreate);
callAll(this._root._oncreate);
callAll(this._root._aftercreate);
this._root._lock = false;
if (this.root._lock) return;
this.root._lock = true;
callAll(this.root._beforecreate);
callAll(this.root._oncreate);
callAll(this.root._aftercreate);
this.root._lock = false;
}

function _set(newState) {
Expand Down
16 changes: 8 additions & 8 deletions test/js/samples/do-use-dataset/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ function get(key) {
function init(component, options) {
component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._root = options._root || component;
component._bind = options._bind;

component.options = options;
component.store = component._root.options.store;
component.root = options.root || component;
component.store = component.root.options.store;
}

function observe(key, callback, options) {
Expand Down Expand Up @@ -129,12 +129,12 @@ function on(eventName, handler) {

function set(newState) {
this._set(assign({}, newState));
if (this._root._lock) return;
this._root._lock = true;
callAll(this._root._beforecreate);
callAll(this._root._oncreate);
callAll(this._root._aftercreate);
this._root._lock = false;
if (this.root._lock) return;
this.root._lock = true;
callAll(this.root._beforecreate);
callAll(this.root._oncreate);
callAll(this.root._aftercreate);
this.root._lock = false;
}

function _set(newState) {
Expand Down
16 changes: 8 additions & 8 deletions test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ function get(key) {
function init(component, options) {
component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._root = options._root || component;
component._bind = options._bind;

component.options = options;
component.store = component._root.options.store;
component.root = options.root || component;
component.store = component.root.options.store;
}

function observe(key, callback, options) {
Expand Down Expand Up @@ -133,12 +133,12 @@ function on(eventName, handler) {

function set(newState) {
this._set(assign({}, newState));
if (this._root._lock) return;
this._root._lock = true;
callAll(this._root._beforecreate);
callAll(this._root._oncreate);
callAll(this._root._aftercreate);
this._root._lock = false;
if (this.root._lock) return;
this.root._lock = true;
callAll(this.root._beforecreate);
callAll(this.root._oncreate);
callAll(this.root._aftercreate);
this.root._lock = false;
}

function _set(newState) {
Expand Down
Loading