remove store option

pull/1348/head
Rich Harris 7 years ago
parent 1143b0a991
commit 2d5b47b8a4

@ -153,7 +153,7 @@ export default function dom(
// generate initial state object // generate initial state object
const expectedProperties = Array.from(generator.expectedProperties); const expectedProperties = Array.from(generator.expectedProperties);
const globals = expectedProperties.filter(prop => globalWhitelist.has(prop)); const globals = expectedProperties.filter(prop => globalWhitelist.has(prop));
const storeProps = options.store || templateProperties.store ? expectedProperties.filter(prop => prop[0] === '$') : []; const storeProps = expectedProperties.filter(prop => prop[0] === '$');
const initialState = []; const initialState = [];
if (globals.length > 0) { if (globals.length > 0) {

@ -159,12 +159,8 @@ function getEventHandler(
dependencies: string[], dependencies: string[],
value: string, value: string,
) { ) {
let storeDependencies = []; const storeDependencies = dependencies.filter(prop => prop[0] === '$').map(prop => prop.slice(1));
dependencies = dependencies.filter(prop => prop[0] !== '$');
if (generator.options.store) {
storeDependencies = dependencies.filter(prop => prop[0] === '$').map(prop => prop.slice(1));
dependencies = dependencies.filter(prop => prop[0] !== '$');
}
if (block.contexts.has(name)) { if (block.contexts.has(name)) {
const tail = attribute.value.type === 'MemberExpression' const tail = attribute.value.type === 'MemberExpression'
@ -207,7 +203,7 @@ function getEventHandler(
let props; let props;
let storeProps; let storeProps;
if (generator.options.store && name[0] === '$') { if (name[0] === '$') {
props = []; props = [];
storeProps = [`${name.slice(1)}: ${value}`]; storeProps = [`${name.slice(1)}: ${value}`];
} else { } else {

@ -217,7 +217,7 @@ export default class Component extends Node {
${binding.dependencies ${binding.dependencies
.map((name: string) => { .map((name: string) => {
const isStoreProp = generator.options.store && name[0] === '$'; const isStoreProp = name[0] === '$';
const prop = isStoreProp ? name.slice(1) : name; const prop = isStoreProp ? name.slice(1) : name;
const newState = isStoreProp ? 'newStoreState' : 'newState'; const newState = isStoreProp ? 'newStoreState' : 'newState';
@ -230,7 +230,7 @@ export default class Component extends Node {
} }
else { else {
const isStoreProp = generator.options.store && key[0] === '$'; const isStoreProp = key[0] === '$';
const prop = isStoreProp ? key.slice(1) : key; const prop = isStoreProp ? key.slice(1) : key;
const newState = isStoreProp ? 'newStoreState' : 'newState'; const newState = isStoreProp ? 'newStoreState' : 'newState';

@ -75,7 +75,7 @@ export default function ssr(
// generate initial state object // generate initial state object
const expectedProperties = Array.from(generator.expectedProperties); const expectedProperties = Array.from(generator.expectedProperties);
const globals = expectedProperties.filter(prop => globalWhitelist.has(prop)); const globals = expectedProperties.filter(prop => globalWhitelist.has(prop));
const storeProps = options.store || templateProperties.store ? expectedProperties.filter(prop => prop[0] === '$') : []; const storeProps = expectedProperties.filter(prop => prop[0] === '$');
const initialState = []; const initialState = [];
if (globals.length > 0) { if (globals.length > 0) {
@ -84,9 +84,7 @@ export default function ssr(
if (storeProps.length > 0) { if (storeProps.length > 0) {
const initialize = `_init([${storeProps.map(prop => `"${prop.slice(1)}"`)}])` const initialize = `_init([${storeProps.map(prop => `"${prop.slice(1)}"`)}])`
if (options.store || templateProperties.store) { initialState.push(`options.store.${initialize}`);
initialState.push(`options.store.${initialize}`);
}
} }
if (templateProperties.data) { if (templateProperties.data) {

@ -103,9 +103,7 @@ export default function visitComponent(
let open = `\${${expression}._render(__result, ${props}`; let open = `\${${expression}._render(__result, ${props}`;
const options = []; const options = [];
if (generator.options.store) { options.push(`store: options.store`);
options.push(`store: options.store`);
}
if (node.children.length) { if (node.children.length) {
const appendTarget: AppendTarget = { const appendTarget: AppendTarget = {

@ -56,12 +56,10 @@ export interface CompileOptions {
dev?: boolean; dev?: boolean;
immutable?: boolean; immutable?: boolean;
shared?: boolean | string; shared?: boolean | string;
cascade?: boolean;
hydratable?: boolean; hydratable?: boolean;
legacy?: boolean; legacy?: boolean;
customElement?: CustomElementOptions | true; customElement?: CustomElementOptions | true;
css?: boolean; css?: boolean;
store?: boolean;
preserveComments?: boolean | false; preserveComments?: boolean | false;

@ -31,24 +31,13 @@ export default function validateEventHandlerCallee(
return; return;
} }
if (name === 'store' && attribute.expression.callee.type === 'MemberExpression') {
if (!validator.options.store) {
validator.warn(attribute.expression, {
code: `options-missing-store`,
message: 'compile with `store: true` in order to call store methods'
});
}
return;
}
if ( if (
(callee.type === 'Identifier' && validBuiltins.has(callee.name)) || (callee.type === 'Identifier' && validBuiltins.has(callee.name)) ||
validator.methods.has(callee.name) validator.methods.has(callee.name)
) )
return; return;
const validCallees = ['this.*', 'event.*', 'options.*', 'console.*'].concat( const validCallees = ['this.*', 'event.*', 'options.*', 'console.*', 'store.*'].concat(
validator.options.store ? 'store.*' : [],
Array.from(validBuiltins), Array.from(validBuiltins),
Array.from(validator.methods.keys()) Array.from(validator.methods.keys())
); );

@ -101,7 +101,7 @@ export default function validate(
stats: Stats, stats: Stats,
options: CompileOptions options: CompileOptions
) { ) {
const { onerror, name, filename, store, dev, parser } = options; const { onerror, name, filename, dev, parser } = options;
try { try {
if (name && !/^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(name)) { if (name && !/^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(name)) {
@ -122,7 +122,6 @@ export default function validate(
const validator = new Validator(parsed, source, stats, { const validator = new Validator(parsed, source, stats, {
name, name,
filename, filename,
store,
dev, dev,
parser parser
}); });

@ -178,13 +178,6 @@ export function showOutput(cwd, options = {}, compile = svelte.compile) {
glob.sync('**/*.html', { cwd }).forEach(file => { glob.sync('**/*.html', { cwd }).forEach(file => {
if (file[0] === '_') return; if (file[0] === '_') return;
// TODO remove this post-v2
if (/-v2\.html$/.test(file)) {
if (!options.v2) return;
} else if (options.v2 && fs.existsSync(`${cwd}/${file.replace('.html', '-v2.html')}`)) {
return;
}
const name = path.basename(file) const name = path.basename(file)
.slice(0, -path.extname(file).length) .slice(0, -path.extname(file).length)
.replace(/^\d/, '_$&') .replace(/^\d/, '_$&')
@ -195,7 +188,7 @@ export function showOutput(cwd, options = {}, compile = svelte.compile) {
Object.assign(options, { Object.assign(options, {
filename: file, filename: file,
name: capitalise(name), name: capitalise(name),
parser: options.v2 ? 'v2' : 'v1' parser: 'v2' // TODO remove
}) })
); );

@ -1,173 +0,0 @@
function noop() {}
function assign(tar, src) {
for (var k in src) tar[k] = src[k];
return tar;
}
function blankObject() {
return Object.create(null);
}
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
this.set = this.get = noop;
if (detach !== false) this._fragment.u();
this._fragment.d();
this._fragment = this._state = null;
}
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function fire(eventName, data) {
var handlers =
eventName in this._handlers && this._handlers[eventName].slice();
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
var handler = handlers[i];
if (!handler.__calling) {
handler.__calling = true;
handler.call(this, data);
handler.__calling = false;
}
}
}
function get() {
return this._state;
}
function init(component, options) {
component._handlers = blankObject();
component._bind = options._bind;
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
}
function on(eventName, handler) {
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
return {
cancel: function() {
var index = handlers.indexOf(handler);
if (~index) handlers.splice(index, 1);
}
};
}
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;
}
function _set(newState) {
var oldState = this._state,
changed = {},
dirty = false;
for (var key in newState) {
if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
this._state = assign(assign({}, oldState), newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
this.fire("state", { changed: changed, current: this._state, previous: oldState });
this._fragment.p(changed, this._state);
this.fire("update", { changed: changed, current: this._state, previous: oldState });
}
}
function callAll(fns) {
while (fns && fns.length) fns.shift()();
}
function _mount(target, anchor) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
}
function _unmount() {
if (this._fragment) this._fragment.u();
}
var proto = {
destroy,
get,
fire,
on,
set,
_recompute: noop,
_set,
_mount,
_unmount,
_differs
};
/* generated by Svelte vX.Y.Z */
function oncreate() {}
function ondestroy() {}
function create_main_fragment(component, state) {
return {
c: noop,
m: noop,
p: noop,
u: noop,
d: noop
};
}
function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._handlers.destroy = [ondestroy];
var self = this;
var _oncreate = function() {
var changed = { };
oncreate.call(self);
self.fire("update", { changed: changed, current: self._state });
};
if (!options.root) {
this._oncreate = [];
}
this._fragment = create_main_fragment(this, this._state);
this.root._oncreate.push(_oncreate);
if (options.target) {
this._fragment.c();
this._mount(options.target, options.anchor);
callAll(this._oncreate);
}
}
assign(SvelteComponent.prototype, proto);
export default SvelteComponent;

@ -1,53 +0,0 @@
/* generated by Svelte vX.Y.Z */
import { assign, callAll, init, noop, proto } from "svelte/shared.js";
function oncreate() {};
function ondestroy() {};
function create_main_fragment(component, state) {
return {
c: noop,
m: noop,
p: noop,
u: noop,
d: noop
};
}
function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._handlers.destroy = [ondestroy];
var self = this;
var _oncreate = function() {
var changed = { };
oncreate.call(self);
self.fire("update", { changed: changed, current: self._state });
};
if (!options.root) {
this._oncreate = [];
}
this._fragment = create_main_fragment(this, this._state);
this.root._oncreate.push(_oncreate);
if (options.target) {
this._fragment.c();
this._mount(options.target, options.anchor);
callAll(this._oncreate);
}
}
assign(SvelteComponent.prototype, proto);
export default SvelteComponent;

@ -1,7 +0,0 @@
<script>
export default {
// this test should be removed in v2
onrender () {},
onteardown () {}
};
</script>

@ -172,12 +172,12 @@ describe.only("runtime", () => {
config.error(assert, err); config.error(assert, err);
} else { } else {
failed.add(dir); failed.add(dir);
showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store, v2: true }, compile); // eslint-disable-line no-console showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store }, compile); // eslint-disable-line no-console
throw err; throw err;
} }
}) })
.then(() => { .then(() => {
if (config.show) showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store, v2: true }, compile); if (config.show) showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store }, compile);
}); });
}); });
} }

Loading…
Cancel
Save