mirror of https://github.com/sveltejs/svelte
integrate CLI - fixes #1360
parent
1130556312
commit
b381aa63a4
@ -0,0 +1,220 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var svelte = require('../compiler/svelte.js');
|
||||
|
||||
var ansi = (strip => ({
|
||||
reset: strip(["\x1b[0m"]),
|
||||
newLine: ["\n", ""],
|
||||
tab: ["\t", ""],
|
||||
|
||||
black: strip(["\x1b[30m", "\x1b[39m"]),
|
||||
red: strip(["\x1b[31m", "\x1b[39m"]),
|
||||
green: strip(["\x1b[32m", "\x1b[39m"]),
|
||||
yellow: strip(["\x1b[33m", "\x1b[39m"]),
|
||||
blue: strip(["\x1b[34m", "\x1b[39m"]),
|
||||
magenta: strip(["\x1b[35m", "\x1b[39m"]),
|
||||
cyan: strip(["\x1b[36m", "\x1b[39m"]),
|
||||
white: strip(["\x1b[37m", "\x1b[39m"]),
|
||||
gray: strip(["\x1B[90m", "\x1b[39m"]),
|
||||
|
||||
bgBlack: strip(["\x1b[40m", "\x1b[49m"]),
|
||||
bgRed: strip(["\x1b[41m", "\x1b[49m"]),
|
||||
bgGreen: strip(["\x1b[42m", "\x1b[49m"]),
|
||||
bgYellow: strip(["\x1b[43m", "\x1b[49m"]),
|
||||
bgBlue: strip(["\x1b[44m", "\x1b[49m"]),
|
||||
bgMagenta: strip(["\x1b[45m", "\x1b[49m"]),
|
||||
bgCyan: strip(["\x1b[46m", "\x1b[49m"]),
|
||||
bgWhite: strip(["\x1b[47m", "\x1b[49m"]),
|
||||
|
||||
dim: strip(["\x1b[2m", "\x1b[22m"]),
|
||||
bold: strip(["\x1b[1m", "\x1b[22m"]),
|
||||
hidden: strip(["\x1b[8m", "\x1b[28m"]),
|
||||
italic: strip(["\x1b[3m", "\x1b[23m"]),
|
||||
underline: strip(["\x1b[4m", "\x1b[24m"]),
|
||||
inverse: strip(["\x1b[7m", "\x1b[27m"]),
|
||||
strikethrough: strip(["\x1b[9m", "\x1b[29m"])
|
||||
}))(
|
||||
ansi =>
|
||||
process.env.FORCE_COLOR ||
|
||||
process.platform === "win32" ||
|
||||
(process.stdout.isTTY && process.env.TERM && process.env.TERM !== "dumb")
|
||||
? ansi
|
||||
: ["", ""]
|
||||
);
|
||||
|
||||
var ansi$1 = /*#__PURE__*/Object.freeze({
|
||||
default: ansi,
|
||||
__moduleExports: ansi
|
||||
});
|
||||
|
||||
var ansi$2 = ( ansi$1 && ansi ) || ansi$1;
|
||||
|
||||
var clorox = (function Clorox(old, close) {
|
||||
const clorox = s => Clorox(clorox.toString(s));
|
||||
|
||||
clorox.toString = s => old + (s || "") + (close || ansi$2.reset[0]);
|
||||
|
||||
Object.keys(ansi$2).map(name => {
|
||||
Object.defineProperty(clorox, name, {
|
||||
get: () => Clorox(old + ansi$2[name][0], (close || "") + ansi$2[name][1])
|
||||
});
|
||||
});
|
||||
|
||||
return clorox
|
||||
})("");
|
||||
|
||||
function stderr(msg) {
|
||||
console.error(msg); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
function error(err) {
|
||||
stderr(`${clorox.red(err.message || err)}`);
|
||||
|
||||
if (err.frame) {
|
||||
stderr(err.frame); // eslint-disable-line no-console
|
||||
} else if (err.stack) {
|
||||
stderr(`${clorox.grey(err.stack)}`);
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function mkdirp(dir) {
|
||||
const parent = path.dirname(dir);
|
||||
if (dir === parent) return;
|
||||
|
||||
mkdirp(parent);
|
||||
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
|
||||
}
|
||||
|
||||
async function compile(input, opts) {
|
||||
if (opts._.length > 0) {
|
||||
error(`Can only compile a single file or directory`);
|
||||
}
|
||||
|
||||
const output = opts.output;
|
||||
|
||||
const stats = fs.statSync(input);
|
||||
const isDir = stats.isDirectory();
|
||||
|
||||
if (isDir) {
|
||||
if (!output) {
|
||||
error(`You must specify an --output (-o) option when compiling a directory of files`);
|
||||
}
|
||||
|
||||
if (opts.name || opts.amdId) {
|
||||
error(`Cannot specify --${opts.name ? 'name' : 'amdId'} when compiling a directory`);
|
||||
}
|
||||
}
|
||||
|
||||
const globals = {};
|
||||
if (opts.globals) {
|
||||
opts.globals.split(',').forEach(pair => {
|
||||
const [key, value] = pair.split(':');
|
||||
globals[key] = value;
|
||||
});
|
||||
}
|
||||
|
||||
const options = {
|
||||
name: opts.name,
|
||||
format: opts.format,
|
||||
sourceMap: opts.sourcemap,
|
||||
globals,
|
||||
css: opts.css !== false,
|
||||
dev: opts.dev,
|
||||
immutable: opts.immutable,
|
||||
generate: opts.generate || 'dom',
|
||||
customElement: opts.customElement,
|
||||
store: opts.store
|
||||
};
|
||||
|
||||
if (isDir) {
|
||||
mkdirp(output);
|
||||
compileDirectory(input, output, options);
|
||||
} else {
|
||||
compileFile(input, output, options);
|
||||
}
|
||||
}
|
||||
|
||||
function compileDirectory(input, output, options) {
|
||||
fs.readdirSync(input).forEach(file => {
|
||||
const src = path.resolve(input, file);
|
||||
const dest = path.resolve(output, file);
|
||||
|
||||
if (path.extname(file) === '.html') {
|
||||
compileFile(
|
||||
src,
|
||||
dest.substring(0, dest.lastIndexOf('.html')) + '.js',
|
||||
options
|
||||
);
|
||||
} else {
|
||||
const stats = fs.statSync(src);
|
||||
if (stats.isDirectory()) {
|
||||
compileDirectory(src, dest, options);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let SOURCEMAPPING_URL = 'sourceMa';
|
||||
SOURCEMAPPING_URL += 'ppingURL';
|
||||
|
||||
function compileFile(input, output, options) {
|
||||
console.error(`compiling ${path.relative(process.cwd(), input)}...`); // eslint-disable-line no-console
|
||||
|
||||
options = Object.assign({}, options);
|
||||
if (!options.name) options.name = getName(input);
|
||||
|
||||
options.filename = input;
|
||||
options.outputFilename = output;
|
||||
|
||||
const { sourceMap } = options;
|
||||
const inline = sourceMap === 'inline';
|
||||
|
||||
let source = fs.readFileSync(input, 'utf-8');
|
||||
if (source[0] === 0xfeff) source = source.slice(1);
|
||||
|
||||
let compiled;
|
||||
|
||||
try {
|
||||
compiled = svelte.compile(source, options);
|
||||
} catch (err) {
|
||||
error(err);
|
||||
}
|
||||
|
||||
const { js } = compiled;
|
||||
|
||||
if (sourceMap) {
|
||||
js.code += `\n//# ${SOURCEMAPPING_URL}=${inline || !output
|
||||
? js.map.toUrl()
|
||||
: `${path.basename(output)}.map`}\n`;
|
||||
}
|
||||
|
||||
if (output) {
|
||||
const outputDir = path.dirname(output);
|
||||
mkdirp(outputDir);
|
||||
fs.writeFileSync(output, js.code);
|
||||
console.error(`wrote ${path.relative(process.cwd(), output)}`); // eslint-disable-line no-console
|
||||
if (sourceMap && !inline) {
|
||||
fs.writeFileSync(`${output}.map`, js.map);
|
||||
console.error(`wrote ${path.relative(process.cwd(), `${output}.map`)}`); // eslint-disable-line no-console
|
||||
}
|
||||
} else {
|
||||
process.stdout.write(js.code);
|
||||
}
|
||||
}
|
||||
|
||||
function getName(input) {
|
||||
return path.basename(input)
|
||||
.replace(path.extname(input), '')
|
||||
.replace(/[^a-zA-Z_$0-9]+/g, '_')
|
||||
.replace(/^_/, '')
|
||||
.replace(/_$/, '')
|
||||
.replace(/^(\d)/, '_$1');
|
||||
}
|
||||
|
||||
exports.compile = compile;
|
@ -0,0 +1,558 @@
|
||||
'use strict';
|
||||
|
||||
const EQQ = /\s|=/;
|
||||
const FLAG = /^-{1,2}/;
|
||||
const PREFIX = /^--no-/i;
|
||||
|
||||
function isBool(any) {
|
||||
return typeof any === 'boolean';
|
||||
}
|
||||
|
||||
function toArr(any) {
|
||||
return Array.isArray(any) ? any : any == null ? [] : [any];
|
||||
}
|
||||
|
||||
function toString(any) {
|
||||
return any == null || any === true ? '' : String(any);
|
||||
}
|
||||
|
||||
function toBool(any) {
|
||||
return any === 'false' ? false : Boolean(any);
|
||||
}
|
||||
|
||||
function toNum(any) {
|
||||
return (!isBool(any) && Number(any)) || any;
|
||||
}
|
||||
|
||||
function getAlibi(names, arr) {
|
||||
if (arr.length === 0) return arr;
|
||||
let k, i = 0, len = arr.length, vals = [];
|
||||
for (; i < len; i++) {
|
||||
k = arr[i];
|
||||
vals.push(k);
|
||||
if (names[k] !== void 0) {
|
||||
vals = vals.concat(names[k]);
|
||||
}
|
||||
}
|
||||
return vals;
|
||||
}
|
||||
|
||||
function typecast(key, val, strings, booleans) {
|
||||
if (strings.indexOf(key) !== -1) return toString(val);
|
||||
if (booleans.indexOf(key) !== -1) return toBool(val);
|
||||
return toNum(val);
|
||||
}
|
||||
|
||||
var lib = function(args, opts) {
|
||||
args = args || [];
|
||||
opts = opts || {};
|
||||
|
||||
opts.string = toArr(opts.string);
|
||||
opts.boolean = toArr(opts.boolean);
|
||||
|
||||
const aliases = {};
|
||||
let k, i, j, x, y, len, type;
|
||||
|
||||
if (opts.alias !== void 0) {
|
||||
for (k in opts.alias) {
|
||||
aliases[k] = toArr(opts.alias[k]);
|
||||
len = aliases[k].length; // save length
|
||||
for (i = 0; i < len; i++) {
|
||||
x = aliases[k][i]; // alias's key name
|
||||
aliases[x] = [k]; // set initial array
|
||||
for (j = 0; j < len; j++) {
|
||||
if (x !== aliases[k][j]) {
|
||||
aliases[x].push(aliases[k][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.default !== void 0) {
|
||||
for (k in opts.default) {
|
||||
type = typeof opts.default[k];
|
||||
opts[type] = (opts[type] || []).concat(k);
|
||||
}
|
||||
}
|
||||
|
||||
// apply to all aliases
|
||||
opts.string = getAlibi(aliases, opts.string);
|
||||
opts.boolean = getAlibi(aliases, opts.boolean);
|
||||
|
||||
let idx = 0;
|
||||
const out = { _: [] };
|
||||
|
||||
while (args[idx] !== void 0) {
|
||||
let incr = 1;
|
||||
const val = args[idx];
|
||||
|
||||
if (val === '--') {
|
||||
out._ = out._.concat(args.slice(idx + 1));
|
||||
break;
|
||||
} else if (!FLAG.test(val)) {
|
||||
out._.push(val);
|
||||
} else if (PREFIX.test(val)) {
|
||||
out[val.replace(PREFIX, '')] = false;
|
||||
} else {
|
||||
let tmp;
|
||||
const segs = val.split(EQQ);
|
||||
const isGroup = segs[0].charCodeAt(1) !== 45; // '-'
|
||||
|
||||
const flag = segs[0].substr(isGroup ? 1 : 2);
|
||||
len = flag.length;
|
||||
const key = isGroup ? flag[len - 1] : flag;
|
||||
|
||||
if (opts.unknown !== void 0 && aliases[key] === void 0) {
|
||||
return opts.unknown(segs[0]);
|
||||
}
|
||||
|
||||
if (segs.length > 1) {
|
||||
tmp = segs[1];
|
||||
} else {
|
||||
tmp = args[idx + 1] || true;
|
||||
FLAG.test(tmp) ? (tmp = true) : (incr = 2);
|
||||
}
|
||||
|
||||
if (isGroup && len > 1) {
|
||||
for (i = len - 1; i--; ) {
|
||||
k = flag[i]; // all but last key
|
||||
out[k] = typecast(k, true, opts.string, opts.boolean);
|
||||
}
|
||||
}
|
||||
|
||||
const value = typecast(key, tmp, opts.string, opts.boolean);
|
||||
out[key] = out[key] !== void 0 ? toArr(out[key]).concat(value) : value;
|
||||
|
||||
// handle discarded args when dealing with booleans
|
||||
if (isBool(value) && !isBool(tmp) && tmp !== 'true' && tmp !== 'false') {
|
||||
out._.push(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
idx += incr;
|
||||
}
|
||||
|
||||
if (opts.default !== void 0) {
|
||||
for (k in opts.default) {
|
||||
if (out[k] === void 0) {
|
||||
out[k] = opts.default[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (k in out) {
|
||||
if (aliases[k] === void 0) continue;
|
||||
y = out[k];
|
||||
len = aliases[k].length;
|
||||
for (i = 0; i < len; i++) {
|
||||
out[aliases[k][i]] = y; // assign value
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
};
|
||||
|
||||
var lib$1 = /*#__PURE__*/Object.freeze({
|
||||
default: lib,
|
||||
__moduleExports: lib
|
||||
});
|
||||
|
||||
/*!
|
||||
* repeat-string <https://github.com/jonschlinkert/repeat-string>
|
||||
*
|
||||
* Copyright (c) 2014-2015, Jon Schlinkert.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Results cache
|
||||
*/
|
||||
|
||||
var res = '';
|
||||
var cache;
|
||||
|
||||
/**
|
||||
* Expose `repeat`
|
||||
*/
|
||||
|
||||
var repeatString = repeat;
|
||||
|
||||
/**
|
||||
* Repeat the given `string` the specified `number`
|
||||
* of times.
|
||||
*
|
||||
* **Example:**
|
||||
*
|
||||
* ```js
|
||||
* var repeat = require('repeat-string');
|
||||
* repeat('A', 5);
|
||||
* //=> AAAAA
|
||||
* ```
|
||||
*
|
||||
* @param {String} `string` The string to repeat
|
||||
* @param {Number} `number` The number of times to repeat the string
|
||||
* @return {String} Repeated string
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function repeat(str, num) {
|
||||
if (typeof str !== 'string') {
|
||||
throw new TypeError('expected a string');
|
||||
}
|
||||
|
||||
// cover common, quick use cases
|
||||
if (num === 1) return str;
|
||||
if (num === 2) return str + str;
|
||||
|
||||
var max = str.length * num;
|
||||
if (cache !== str || typeof cache === 'undefined') {
|
||||
cache = str;
|
||||
res = '';
|
||||
} else if (res.length >= max) {
|
||||
return res.substr(0, max);
|
||||
}
|
||||
|
||||
while (max > res.length && num > 1) {
|
||||
if (num & 1) {
|
||||
res += str;
|
||||
}
|
||||
|
||||
num >>= 1;
|
||||
str += str;
|
||||
}
|
||||
|
||||
res += str;
|
||||
res = res.substr(0, max);
|
||||
return res;
|
||||
}
|
||||
|
||||
var repeatString$1 = /*#__PURE__*/Object.freeze({
|
||||
default: repeatString,
|
||||
__moduleExports: repeatString
|
||||
});
|
||||
|
||||
var repeat$1 = ( repeatString$1 && repeatString ) || repeatString$1;
|
||||
|
||||
var padRight = function padLeft(val, num, str) {
|
||||
var padding = '';
|
||||
var diff = num - val.length;
|
||||
|
||||
// Breakpoints based on benchmarks to use the fastest approach
|
||||
// for the given number of zeros
|
||||
if (diff <= 5 && !str) {
|
||||
padding = '00000';
|
||||
} else if (diff <= 25 && !str) {
|
||||
padding = '000000000000000000000000000';
|
||||
} else {
|
||||
return val + repeat$1(str || '0', diff);
|
||||
}
|
||||
|
||||
return val + padding.slice(0, diff);
|
||||
};
|
||||
|
||||
var padRight$1 = /*#__PURE__*/Object.freeze({
|
||||
default: padRight,
|
||||
__moduleExports: padRight
|
||||
});
|
||||
|
||||
var rpad = ( padRight$1 && padRight ) || padRight$1;
|
||||
|
||||
const GAP = 4;
|
||||
const __ = ' ';
|
||||
const ALL = '__all__';
|
||||
const DEF = '__default__';
|
||||
const NL = '\n';
|
||||
|
||||
function format(arr) {
|
||||
if (!arr.length) return '';
|
||||
let len = maxLen( arr.map(x => x[0]) ) + GAP;
|
||||
let join = a => rpad(a[0], len, ' ') + a[1] + (a[2] == null ? '' : ` (default ${a[2]})`);
|
||||
return arr.map(join);
|
||||
}
|
||||
|
||||
function maxLen(arr) {
|
||||
let c=0, d=0, l=0, i=arr.length;
|
||||
if (i) while (i--) {
|
||||
d = arr[i].length;
|
||||
if (d > c) {
|
||||
l = i; c = d;
|
||||
}
|
||||
}
|
||||
return arr[l].length;
|
||||
}
|
||||
|
||||
function noop(s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
function section(str, arr, fn) {
|
||||
if (!arr || !arr.length) return '';
|
||||
let i=0, out='';
|
||||
out += (NL + __ + str);
|
||||
for (; i < arr.length; i++) {
|
||||
out += (NL + __ + __ + fn(arr[i]));
|
||||
}
|
||||
return out + NL;
|
||||
}
|
||||
|
||||
var help = function (bin, tree, key) {
|
||||
let out='', cmd=tree[key], pfx=`$ ${bin}`, all=tree[ALL];
|
||||
let prefix = s => `${pfx} ${s}`;
|
||||
|
||||
// update ALL & CMD options
|
||||
all.options.push(['-h, --help', 'Displays this message']);
|
||||
cmd.options = (cmd.options || []).concat(all.options);
|
||||
|
||||
// write options placeholder
|
||||
(cmd.options.length > 0) && (cmd.usage += ' [options]');
|
||||
|
||||
// description ~> text only; usage ~> prefixed
|
||||
out += section('Description', cmd.describe, noop);
|
||||
out += section('Usage', [cmd.usage], prefix);
|
||||
|
||||
if (key === DEF) {
|
||||
// General help :: print all non-internal commands & their 1st line of text
|
||||
let cmds = Object.keys(tree).filter(k => !/__/.test(k));
|
||||
let text = cmds.map(k => [k, (tree[k].describe || [''])[0]]);
|
||||
out += section('Available Commands', format(text), noop);
|
||||
|
||||
out += (NL + __ + 'For more info, run any command with the `--help` flag');
|
||||
cmds.slice(0, 2).forEach(k => {
|
||||
out += (NL + __ + __ + `${pfx} ${k} --help`);
|
||||
});
|
||||
out += NL;
|
||||
}
|
||||
|
||||
out += section('Options', format(cmd.options), noop);
|
||||
out += section('Examples', cmd.examples.map(prefix), noop);
|
||||
|
||||
return out;
|
||||
};
|
||||
|
||||
var error = function (bin, str, num=1) {
|
||||
let out = section('ERROR', [str], noop);
|
||||
out += (NL + __ + `Run \`$ ${bin} --help\` for more info.` + NL);
|
||||
console.error(out);
|
||||
process.exit(num);
|
||||
};
|
||||
|
||||
// Strips leading `-|--` & extra space(s)
|
||||
var parse = function (str) {
|
||||
return (str || '').split(/^-{1,2}|,|\s+-{1,2}|\s+/).filter(Boolean);
|
||||
};
|
||||
|
||||
// @see https://stackoverflow.com/a/18914855/3577474
|
||||
var sentences = function (str) {
|
||||
return (str || '').replace(/([.?!])\s*(?=[A-Z])/g, '$1|').split('|');
|
||||
};
|
||||
|
||||
var utils = {
|
||||
help: help,
|
||||
error: error,
|
||||
parse: parse,
|
||||
sentences: sentences
|
||||
};
|
||||
|
||||
var utils$1 = /*#__PURE__*/Object.freeze({
|
||||
default: utils,
|
||||
__moduleExports: utils,
|
||||
help: help,
|
||||
error: error,
|
||||
parse: parse,
|
||||
sentences: sentences
|
||||
});
|
||||
|
||||
var mri = ( lib$1 && lib ) || lib$1;
|
||||
|
||||
var $ = ( utils$1 && utils ) || utils$1;
|
||||
|
||||
const ALL$1 = '__all__';
|
||||
const DEF$1 = '__default__';
|
||||
|
||||
class Sade {
|
||||
constructor(name) {
|
||||
this.tree = {};
|
||||
this.name = name;
|
||||
this.ver = '0.0.0';
|
||||
this.default = '';
|
||||
// set internal shapes;
|
||||
this.command(ALL$1);
|
||||
this.command(`${DEF$1} <command>`)
|
||||
.option('-v, --version', 'Displays current version');
|
||||
this.curr = ''; // reset
|
||||
}
|
||||
|
||||
command(str, desc, opts) {
|
||||
let cmd=[], usage=[], rgx=/(\[|<)/;
|
||||
// All non-([|<) are commands
|
||||
str.split(/\s+/).forEach(x => {
|
||||
(rgx.test(x.charAt(0)) ? usage : cmd).push(x);
|
||||
});
|
||||
|
||||
// Back to string~!
|
||||
cmd = cmd.join(' ');
|
||||
|
||||
if (cmd in this.tree) {
|
||||
throw new Error(`Command already exists: ${cmd}`);
|
||||
}
|
||||
|
||||
this.curr = cmd;
|
||||
(opts && opts.default) && (this.default=cmd);
|
||||
|
||||
!~cmd.indexOf('__') && usage.unshift(cmd); // re-include `cmd`
|
||||
usage = usage.join(' '); // to string
|
||||
|
||||
this.tree[cmd] = { usage, options:[], alias:{}, default:{}, examples:[] };
|
||||
desc && this.describe(desc);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
describe(str) {
|
||||
this.tree[this.curr || DEF$1].describe = Array.isArray(str) ? str : $.sentences(str);
|
||||
return this;
|
||||
}
|
||||
|
||||
option(str, desc, val) {
|
||||
let cmd = this.tree[ this.curr || ALL$1 ];
|
||||
|
||||
let [flag, alias] = $.parse(str);
|
||||
(alias && alias.length > 1) && ([flag, alias]=[alias, flag]);
|
||||
|
||||
str = `--${flag}`;
|
||||
if (alias && alias.length > 0) {
|
||||
str = `-${alias}, ${str}`;
|
||||
let old = cmd.alias[alias];
|
||||
cmd.alias[alias] = (old || []).concat(flag);
|
||||
}
|
||||
|
||||
let arr = [str, desc || ''];
|
||||
|
||||
if (val !== void 0) {
|
||||
arr.push(val);
|
||||
cmd.default[flag] = val;
|
||||
}
|
||||
|
||||
cmd.options.push(arr);
|
||||
return this;
|
||||
}
|
||||
|
||||
action(handler) {
|
||||
this.tree[ this.curr || DEF$1 ].handler = handler;
|
||||
return this;
|
||||
}
|
||||
|
||||
example(str) {
|
||||
this.tree[ this.curr || DEF$1 ].examples.push(str);
|
||||
return this;
|
||||
}
|
||||
|
||||
version(str) {
|
||||
this.ver = str;
|
||||
return this;
|
||||
}
|
||||
|
||||
parse(arr, opts={}) {
|
||||
let offset = 2; // argv slicer
|
||||
let alias = { h:'help', v:'version' };
|
||||
let argv = mri(arr.slice(offset), { alias });
|
||||
let bin = this.name;
|
||||
|
||||
// Loop thru possible command(s)
|
||||
let tmp, name='';
|
||||
let i=1, len=argv._.length + 1;
|
||||
for (; i < len; i++) {
|
||||
tmp = argv._.slice(0, i).join(' ');
|
||||
if (this.tree[tmp] !== void 0) {
|
||||
name=tmp; offset=(i + 2); // argv slicer
|
||||
}
|
||||
}
|
||||
|
||||
let cmd = this.tree[name];
|
||||
let isVoid = (cmd === void 0);
|
||||
|
||||
if (isVoid) {
|
||||
if (this.default) {
|
||||
name = this.default;
|
||||
cmd = this.tree[name];
|
||||
arr.unshift(name);
|
||||
offset++;
|
||||
} else if (name) {
|
||||
return $.error(bin, `Invalid command: ${name}`);
|
||||
} //=> else: cmd not specified, wait for now...
|
||||
}
|
||||
|
||||
if (argv.version) {
|
||||
return console.log(`${bin}, ${this.ver}`);
|
||||
}
|
||||
|
||||
if (argv.help) {
|
||||
return this.help(!isVoid && name);
|
||||
}
|
||||
|
||||
if (cmd === void 0) {
|
||||
return $.error(bin, 'No command specified.');
|
||||
}
|
||||
|
||||
let all = this.tree[ALL$1];
|
||||
// merge all objects :: params > command > all
|
||||
opts.alias = Object.assign(all.alias, cmd.alias, opts.alias);
|
||||
opts.default = Object.assign(all.default, cmd.default, opts.default);
|
||||
|
||||
let vals = mri(arr.slice(offset), opts);
|
||||
let segs = cmd.usage.split(/\s+/);
|
||||
let reqs = segs.filter(x => x.charAt(0)==='<');
|
||||
let args = vals._.splice(0, reqs.length);
|
||||
|
||||
if (args.length < reqs.length) {
|
||||
name && (bin += ` ${name}`); // for help text
|
||||
return $.error(bin, 'Insufficient arguments!');
|
||||
}
|
||||
|
||||
segs.filter(x => x.charAt(0)==='[').forEach(_ => {
|
||||
args.push(vals._.pop()); // adds `undefined` per [slot] if no more
|
||||
});
|
||||
|
||||
args.push(vals); // flags & co are last
|
||||
let handler = cmd.handler;
|
||||
return opts.lazy ? { args, name, handler } : handler.apply(null, args);
|
||||
}
|
||||
|
||||
help(str) {
|
||||
console.log(
|
||||
$.help(this.name, this.tree, str || DEF$1)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
var lib$2 = str => new Sade(str);
|
||||
|
||||
var version = "2.3.0";
|
||||
|
||||
const prog = lib$2('svelte-cli').version(version);
|
||||
|
||||
prog
|
||||
.command('compile <input>')
|
||||
|
||||
.option('-o, --output', 'Output (if absent, prints to stdout)')
|
||||
.option('-f, --format', 'Type of output (amd, cjs, es, iife, umd)')
|
||||
.option('-g, --globals', 'Comma-separate list of `module ID:Global` pairs')
|
||||
.option('-n, --name', 'Name for IIFE/UMD export (inferred from filename by default)')
|
||||
.option('-m, --sourcemap', 'Generate sourcemap (`-m inline` for inline map)')
|
||||
.option('-d, --dev', 'Add dev mode warnings and errors')
|
||||
.option('--amdId', 'ID for AMD module (default is anonymous)')
|
||||
.option('--generate', 'Change generate format between `dom` and `ssr`')
|
||||
.option('--no-css', `Don't include CSS (useful with SSR)`)
|
||||
.option('--immutable', 'Support immutable data structures')
|
||||
|
||||
.example('compile App.html > App.js')
|
||||
.example('compile src -o dest')
|
||||
.example('compile -f umd MyComponent.html > MyComponent.js')
|
||||
|
||||
.action(async (input, opts) => {
|
||||
const { compile } = await Promise.resolve(require("./compile.js"));
|
||||
compile(input, opts);
|
||||
})
|
||||
|
||||
.parse(process.argv);
|
@ -0,0 +1,139 @@
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as svelte from 'svelte';
|
||||
import error from './error.js';
|
||||
|
||||
function mkdirp(dir) {
|
||||
const parent = path.dirname(dir);
|
||||
if (dir === parent) return;
|
||||
|
||||
mkdirp(parent);
|
||||
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
|
||||
}
|
||||
|
||||
export async function compile(input, opts) {
|
||||
if (opts._.length > 0) {
|
||||
error(`Can only compile a single file or directory`);
|
||||
}
|
||||
|
||||
const output = opts.output;
|
||||
|
||||
const stats = fs.statSync(input);
|
||||
const isDir = stats.isDirectory();
|
||||
|
||||
if (isDir) {
|
||||
if (!output) {
|
||||
error(`You must specify an --output (-o) option when compiling a directory of files`);
|
||||
}
|
||||
|
||||
if (opts.name || opts.amdId) {
|
||||
error(`Cannot specify --${opts.name ? 'name' : 'amdId'} when compiling a directory`);
|
||||
}
|
||||
}
|
||||
|
||||
const globals = {};
|
||||
if (opts.globals) {
|
||||
opts.globals.split(',').forEach(pair => {
|
||||
const [key, value] = pair.split(':');
|
||||
globals[key] = value;
|
||||
});
|
||||
}
|
||||
|
||||
const options = {
|
||||
name: opts.name,
|
||||
format: opts.format,
|
||||
sourceMap: opts.sourcemap,
|
||||
globals,
|
||||
css: opts.css !== false,
|
||||
dev: opts.dev,
|
||||
immutable: opts.immutable,
|
||||
generate: opts.generate || 'dom',
|
||||
customElement: opts.customElement,
|
||||
store: opts.store
|
||||
};
|
||||
|
||||
if (isDir) {
|
||||
mkdirp(output);
|
||||
compileDirectory(input, output, options);
|
||||
} else {
|
||||
compileFile(input, output, options);
|
||||
}
|
||||
}
|
||||
|
||||
function compileDirectory(input, output, options) {
|
||||
fs.readdirSync(input).forEach(file => {
|
||||
const src = path.resolve(input, file);
|
||||
const dest = path.resolve(output, file);
|
||||
|
||||
if (path.extname(file) === '.html') {
|
||||
compileFile(
|
||||
src,
|
||||
dest.substring(0, dest.lastIndexOf('.html')) + '.js',
|
||||
options
|
||||
);
|
||||
} else {
|
||||
const stats = fs.statSync(src);
|
||||
if (stats.isDirectory()) {
|
||||
compileDirectory(src, dest, options);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let SOURCEMAPPING_URL = 'sourceMa';
|
||||
SOURCEMAPPING_URL += 'ppingURL';
|
||||
|
||||
function compileFile(input, output, options) {
|
||||
console.error(`compiling ${path.relative(process.cwd(), input)}...`); // eslint-disable-line no-console
|
||||
|
||||
options = Object.assign({}, options);
|
||||
if (!options.name) options.name = getName(input);
|
||||
|
||||
options.filename = input;
|
||||
options.outputFilename = output;
|
||||
|
||||
const { sourceMap } = options;
|
||||
const inline = sourceMap === 'inline';
|
||||
|
||||
let source = fs.readFileSync(input, 'utf-8');
|
||||
if (source[0] === 0xfeff) source = source.slice(1);
|
||||
|
||||
let compiled;
|
||||
|
||||
try {
|
||||
compiled = svelte.compile(source, options);
|
||||
} catch (err) {
|
||||
error(err);
|
||||
}
|
||||
|
||||
const { js } = compiled;
|
||||
|
||||
if (sourceMap) {
|
||||
js.code += `\n//# ${SOURCEMAPPING_URL}=${inline || !output
|
||||
? js.map.toUrl()
|
||||
: `${path.basename(output)}.map`}\n`;
|
||||
}
|
||||
|
||||
if (output) {
|
||||
const outputDir = path.dirname(output);
|
||||
mkdirp(outputDir);
|
||||
fs.writeFileSync(output, js.code);
|
||||
console.error(`wrote ${path.relative(process.cwd(), output)}`); // eslint-disable-line no-console
|
||||
if (sourceMap && !inline) {
|
||||
fs.writeFileSync(`${output}.map`, js.map);
|
||||
console.error(`wrote ${path.relative(process.cwd(), `${output}.map`)}`); // eslint-disable-line no-console
|
||||
}
|
||||
} else {
|
||||
process.stdout.write(js.code);
|
||||
}
|
||||
}
|
||||
|
||||
function getName(input) {
|
||||
return path
|
||||
.basename(input)
|
||||
.replace(path.extname(input), '')
|
||||
.replace(/[^a-zA-Z_$0-9]+/g, '_')
|
||||
.replace(/^_/, '')
|
||||
.replace(/_$/, '')
|
||||
.replace(/^(\d)/, '_$1');
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
import clorox from 'clorox';
|
||||
|
||||
function stderr(msg) {
|
||||
console.error(msg); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
export default function error(err) {
|
||||
stderr(`${clorox.red(err.message || err)}`);
|
||||
|
||||
if (err.frame) {
|
||||
stderr(err.frame); // eslint-disable-line no-console
|
||||
} else if (err.stack) {
|
||||
stderr(`${clorox.grey(err.stack)}`);
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
import sade from 'sade';
|
||||
import * as pkg from '../../package.json';
|
||||
|
||||
const prog = sade('svelte-cli').version(pkg.version);
|
||||
|
||||
prog
|
||||
.command('compile <input>')
|
||||
|
||||
.option('-o, --output', 'Output (if absent, prints to stdout)')
|
||||
.option('-f, --format', 'Type of output (amd, cjs, es, iife, umd)')
|
||||
.option('-g, --globals', 'Comma-separate list of `module ID:Global` pairs')
|
||||
.option('-n, --name', 'Name for IIFE/UMD export (inferred from filename by default)')
|
||||
.option('-m, --sourcemap', 'Generate sourcemap (`-m inline` for inline map)')
|
||||
.option('-d, --dev', 'Add dev mode warnings and errors')
|
||||
.option('--amdId', 'ID for AMD module (default is anonymous)')
|
||||
.option('--generate', 'Change generate format between `dom` and `ssr`')
|
||||
.option('--no-css', `Don't include CSS (useful with SSR)`)
|
||||
.option('--immutable', 'Support immutable data structures')
|
||||
|
||||
.example('compile App.html > App.js')
|
||||
.example('compile src -o dest')
|
||||
.example('compile -f umd MyComponent.html > MyComponent.js')
|
||||
|
||||
.action(async (input, opts) => {
|
||||
const { compile } = await import('./compile.js');
|
||||
compile(input, opts);
|
||||
})
|
||||
|
||||
.parse(process.argv);
|
@ -0,0 +1,76 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const child_process = require('child_process');
|
||||
const assert = require('assert');
|
||||
const glob = require('tiny-glob/sync.js');
|
||||
|
||||
const bin = path.resolve(`svelte`);
|
||||
|
||||
function normalize(str) {
|
||||
return str.replace(/^\s+$/gm, '').trim();
|
||||
}
|
||||
|
||||
const cwd = process.cwd();
|
||||
|
||||
describe('svelte-cli', () => {
|
||||
afterEach(() => {
|
||||
process.chdir(cwd);
|
||||
});
|
||||
|
||||
fs.readdirSync('test/cli/samples').forEach(dir => {
|
||||
if (dir[0] === '.') return;
|
||||
|
||||
// append .solo to test dir to only run that test
|
||||
const solo = /\.solo$/.test(dir);
|
||||
|
||||
(solo ? it.only : it)(dir, done => {
|
||||
process.chdir(`${__dirname}/samples/${dir}`);
|
||||
|
||||
const command = fs.readFileSync('command.sh', 'utf-8');
|
||||
|
||||
child_process.exec(`
|
||||
alias svelte=${bin}
|
||||
mkdir -p actual
|
||||
rm -rf actual/*
|
||||
${command}
|
||||
`, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
return;
|
||||
}
|
||||
|
||||
const actual = glob('**', { cwd: 'actual', filesOnly: true })
|
||||
.map(file => {
|
||||
return {
|
||||
file,
|
||||
contents: normalize(fs.readFileSync(`actual/${file}`, 'utf-8'))
|
||||
};
|
||||
});
|
||||
|
||||
const expected = glob('**', { cwd: 'expected', filesOnly: true })
|
||||
.map(file => {
|
||||
return {
|
||||
file,
|
||||
contents: normalize(
|
||||
fs.readFileSync(`expected/${file}`, 'utf-8')
|
||||
)
|
||||
};
|
||||
});
|
||||
|
||||
actual.forEach((a, i) => {
|
||||
const e = expected[i];
|
||||
|
||||
assert.equal(a.file, e.file, 'File list mismatch');
|
||||
|
||||
if (/\.map$/.test(a.file)) {
|
||||
assert.deepEqual(JSON.parse(a.contents), JSON.parse(e.contents));
|
||||
} else {
|
||||
assert.equal(a.contents, e.contents);
|
||||
}
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,173 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
p.textContent = "Hello world!";
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Main;
|
@ -0,0 +1 @@
|
||||
svelte compile src/Main.html > actual/Main.js
|
@ -0,0 +1,173 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
p.textContent = "Hello world!";
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Main;
|
@ -0,0 +1 @@
|
||||
<p>Hello world!</p>
|
@ -0,0 +1,198 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
p.textContent = "Hello world!";
|
||||
this.c = noop;
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
class Main extends HTMLElement {
|
||||
constructor(options = {}) {
|
||||
super();
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
this.attachShadow({ mode: 'open' });
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
this._fragment.c();
|
||||
this._fragment.m(this.shadowRoot, null);
|
||||
|
||||
if (options.target) this._mount(options.target, options.anchor);
|
||||
}
|
||||
|
||||
static get observedAttributes() {
|
||||
return [];
|
||||
}
|
||||
|
||||
attributeChangedCallback(attr, oldValue, newValue) {
|
||||
this.set({ [attr]: newValue });
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
assign(Main.prototype, {
|
||||
_mount(target, anchor) {
|
||||
target.insertBefore(this, anchor);
|
||||
},
|
||||
|
||||
_unmount() {
|
||||
this.parentNode.removeChild(this);
|
||||
}
|
||||
});
|
||||
|
||||
customElements.define("my-element", Main);
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Main;
|
@ -0,0 +1 @@
|
||||
svelte compile src/Main.html --customElement > actual/Main.js
|
@ -0,0 +1,198 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
p.textContent = "Hello world!";
|
||||
this.c = noop;
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
class Main extends HTMLElement {
|
||||
constructor(options = {}) {
|
||||
super();
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
this.attachShadow({ mode: 'open' });
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
this._fragment.c();
|
||||
this._fragment.m(this.shadowRoot, null);
|
||||
|
||||
if (options.target) this._mount(options.target, options.anchor);
|
||||
}
|
||||
|
||||
static get observedAttributes() {
|
||||
return [];
|
||||
}
|
||||
|
||||
attributeChangedCallback(attr, oldValue, newValue) {
|
||||
this.set({ [attr]: newValue });
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
assign(Main.prototype, {
|
||||
_mount(target, anchor) {
|
||||
target.insertBefore(this, anchor);
|
||||
},
|
||||
|
||||
_unmount() {
|
||||
this.parentNode.removeChild(this);
|
||||
}
|
||||
});
|
||||
|
||||
customElements.define("my-element", Main);
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Main;
|
@ -0,0 +1,7 @@
|
||||
<p>Hello world!</p>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
tag: 'my-element'
|
||||
};
|
||||
</script>
|
@ -0,0 +1,197 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
p.textContent = "Hello world!";
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
this._debugName = '<Main>';
|
||||
if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option");
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroyDev,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: setDev,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._checkReadOnly = function _checkReadOnly(newState) {
|
||||
};
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroyDev(detach) {
|
||||
destroy.call(this, detach);
|
||||
this.destroy = function() {
|
||||
console.warn('Component was already destroyed');
|
||||
};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 setDev(newState) {
|
||||
if (typeof newState !== 'object') {
|
||||
throw new Error(
|
||||
this._debugName + '.set was called without an object of data key-values to update.'
|
||||
);
|
||||
}
|
||||
|
||||
this._checkReadOnly(newState);
|
||||
set.call(this, newState);
|
||||
}
|
||||
|
||||
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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
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 callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Main;
|
@ -0,0 +1 @@
|
||||
svelte compile src/Main.html -d > actual/Main.js
|
@ -0,0 +1,197 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
p.textContent = "Hello world!";
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
this._debugName = '<Main>';
|
||||
if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option");
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroyDev,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: setDev,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._checkReadOnly = function _checkReadOnly(newState) {
|
||||
};
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroyDev(detach) {
|
||||
destroy.call(this, detach);
|
||||
this.destroy = function() {
|
||||
console.warn('Component was already destroyed');
|
||||
};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 setDev(newState) {
|
||||
if (typeof newState !== 'object') {
|
||||
throw new Error(
|
||||
this._debugName + '.set was called without an object of data key-values to update.'
|
||||
);
|
||||
}
|
||||
|
||||
this._checkReadOnly(newState);
|
||||
set.call(this, newState);
|
||||
}
|
||||
|
||||
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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
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 callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Main;
|
@ -0,0 +1 @@
|
||||
<p>Hello world!</p>
|
@ -0,0 +1,181 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
import Widget from './Widget.html';
|
||||
|
||||
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
|
||||
var widget = new Widget({
|
||||
root: component.root
|
||||
});
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
widget._fragment.c();
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
widget._mount(target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
widget._unmount();
|
||||
},
|
||||
|
||||
d: function destroy() {
|
||||
widget.destroy(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
if (!options.root) {
|
||||
this._oncreate = [];
|
||||
this._beforecreate = [];
|
||||
this._aftercreate = [];
|
||||
}
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
|
||||
this._lock = true;
|
||||
callAll(this._beforecreate);
|
||||
callAll(this._oncreate);
|
||||
callAll(this._aftercreate);
|
||||
this._lock = false;
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function noop() {}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
export default Main;
|
||||
//# sourceMappingURL=Main.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"Main.js","sources":["../src/Main.html"],"sourcesContent":["<Widget/>\n\n<script>\n\timport Widget from './Widget.html';\n\n\texport default {\n\t\tcomponents: {\n\t\t\tWidget\n\t\t}\n\t};\n</script>"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
@ -0,0 +1,174 @@
|
||||
/* src/Widget.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
p.textContent = "widget";
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Widget(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Widget.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Widget.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Widget;
|
||||
//# sourceMappingURL=Widget.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"Widget.js","sources":["../src/Widget.html"],"sourcesContent":["<p>widget</p>"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
@ -0,0 +1 @@
|
||||
svelte compile src -m -o actual
|
@ -0,0 +1,181 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
import Widget from './Widget.html';
|
||||
|
||||
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
|
||||
var widget = new Widget({
|
||||
root: component.root
|
||||
});
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
widget._fragment.c();
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
widget._mount(target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
widget._unmount();
|
||||
},
|
||||
|
||||
d: function destroy() {
|
||||
widget.destroy(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
if (!options.root) {
|
||||
this._oncreate = [];
|
||||
this._beforecreate = [];
|
||||
this._aftercreate = [];
|
||||
}
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
|
||||
this._lock = true;
|
||||
callAll(this._beforecreate);
|
||||
callAll(this._oncreate);
|
||||
callAll(this._aftercreate);
|
||||
this._lock = false;
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function noop() {}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
export default Main;
|
||||
//# sourceMappingURL=Main.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"Main.js","sources":["../src/Main.html"],"sourcesContent":["<Widget/>\n\n<script>\n\timport Widget from './Widget.html';\n\n\texport default {\n\t\tcomponents: {\n\t\t\tWidget\n\t\t}\n\t};\n</script>"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
@ -0,0 +1,174 @@
|
||||
/* src/Widget.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
p.textContent = "widget";
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Widget(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Widget.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Widget.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Widget;
|
||||
//# sourceMappingURL=Widget.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"Widget.js","sources":["../src/Widget.html"],"sourcesContent":["<p>widget</p>"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
@ -0,0 +1,11 @@
|
||||
<Widget/>
|
||||
|
||||
<script>
|
||||
import Widget from './Widget.html';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Widget
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1 @@
|
||||
<p>widget</p>
|
@ -0,0 +1,180 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
import Widget from './widget/Widget.html';
|
||||
|
||||
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
|
||||
var widget = new Widget({
|
||||
root: component.root
|
||||
});
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
widget._fragment.c();
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
widget._mount(target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
widget._unmount();
|
||||
},
|
||||
|
||||
d: function destroy() {
|
||||
widget.destroy(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
if (!options.root) {
|
||||
this._oncreate = [];
|
||||
this._beforecreate = [];
|
||||
this._aftercreate = [];
|
||||
}
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
|
||||
this._lock = true;
|
||||
callAll(this._beforecreate);
|
||||
callAll(this._oncreate);
|
||||
callAll(this._aftercreate);
|
||||
this._lock = false;
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function noop() {}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
export default Main;
|
@ -0,0 +1,173 @@
|
||||
/* src/widget/Widget.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
p.textContent = "widget";
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Widget(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Widget.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Widget.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Widget;
|
@ -0,0 +1 @@
|
||||
svelte compile src -o actual
|
@ -0,0 +1,180 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
import Widget from './widget/Widget.html';
|
||||
|
||||
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
|
||||
var widget = new Widget({
|
||||
root: component.root
|
||||
});
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
widget._fragment.c();
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
widget._mount(target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
widget._unmount();
|
||||
},
|
||||
|
||||
d: function destroy() {
|
||||
widget.destroy(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
if (!options.root) {
|
||||
this._oncreate = [];
|
||||
this._beforecreate = [];
|
||||
this._aftercreate = [];
|
||||
}
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
|
||||
this._lock = true;
|
||||
callAll(this._beforecreate);
|
||||
callAll(this._oncreate);
|
||||
callAll(this._aftercreate);
|
||||
this._lock = false;
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function noop() {}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
export default Main;
|
@ -0,0 +1,173 @@
|
||||
/* src/widget/Widget.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
p.textContent = "widget";
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Widget(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Widget.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Widget.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Widget;
|
@ -0,0 +1,11 @@
|
||||
<Widget/>
|
||||
|
||||
<script>
|
||||
import Widget from './widget/Widget.html';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Widget
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1 @@
|
||||
<p>widget</p>
|
@ -0,0 +1,180 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
import Widget from './Widget.html';
|
||||
|
||||
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
|
||||
var widget = new Widget({
|
||||
root: component.root
|
||||
});
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
widget._fragment.c();
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
widget._mount(target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
widget._unmount();
|
||||
},
|
||||
|
||||
d: function destroy() {
|
||||
widget.destroy(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
if (!options.root) {
|
||||
this._oncreate = [];
|
||||
this._beforecreate = [];
|
||||
this._aftercreate = [];
|
||||
}
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
|
||||
this._lock = true;
|
||||
callAll(this._beforecreate);
|
||||
callAll(this._oncreate);
|
||||
callAll(this._aftercreate);
|
||||
this._lock = false;
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function noop() {}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
export default Main;
|
@ -0,0 +1,173 @@
|
||||
/* src/Widget.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
p.textContent = "widget";
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Widget(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Widget.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Widget.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Widget;
|
@ -0,0 +1 @@
|
||||
svelte compile src -o actual
|
@ -0,0 +1,180 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
import Widget from './Widget.html';
|
||||
|
||||
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
|
||||
var widget = new Widget({
|
||||
root: component.root
|
||||
});
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
widget._fragment.c();
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
widget._mount(target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
widget._unmount();
|
||||
},
|
||||
|
||||
d: function destroy() {
|
||||
widget.destroy(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
if (!options.root) {
|
||||
this._oncreate = [];
|
||||
this._beforecreate = [];
|
||||
this._aftercreate = [];
|
||||
}
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
|
||||
this._lock = true;
|
||||
callAll(this._beforecreate);
|
||||
callAll(this._oncreate);
|
||||
callAll(this._aftercreate);
|
||||
this._lock = false;
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function noop() {}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
export default Main;
|
@ -0,0 +1,173 @@
|
||||
/* src/Widget.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
p.textContent = "widget";
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Widget(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Widget.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Widget.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Widget;
|
@ -0,0 +1,11 @@
|
||||
<Widget/>
|
||||
|
||||
<script>
|
||||
import Widget from './Widget.html';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Widget
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1 @@
|
||||
<p>widget</p>
|
@ -0,0 +1,197 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
var Main = (function(answer) { "use strict";
|
||||
answer = (answer && answer.__esModule) ? answer["default"] : answer;
|
||||
|
||||
function data() {
|
||||
return {
|
||||
answer: answer
|
||||
};
|
||||
};
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p, text, text_1;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
text = createText("The answer is ");
|
||||
text_1 = createText(ctx.answer);
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
appendNode(text, p);
|
||||
appendNode(text_1, p);
|
||||
},
|
||||
|
||||
p: function update(changed, ctx) {
|
||||
if (changed.answer) {
|
||||
text_1.data = ctx.answer;
|
||||
}
|
||||
},
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
init(this, options);
|
||||
this._state = assign(data(), options.data);
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function createText(data) {
|
||||
return document.createTextNode(data);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function appendNode(node, target) {
|
||||
target.appendChild(node);
|
||||
}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
return Main;
|
||||
}(theAnswer));
|
@ -0,0 +1 @@
|
||||
svelte compile src/Main.html -f iife -g the-answer:theAnswer > actual/Main.js
|
@ -0,0 +1,197 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
var Main = (function(answer) { "use strict";
|
||||
answer = (answer && answer.__esModule) ? answer["default"] : answer;
|
||||
|
||||
function data() {
|
||||
return {
|
||||
answer: answer
|
||||
};
|
||||
};
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p, text, text_1;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
text = createText("The answer is ");
|
||||
text_1 = createText(ctx.answer);
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
appendNode(text, p);
|
||||
appendNode(text_1, p);
|
||||
},
|
||||
|
||||
p: function update(changed, ctx) {
|
||||
if (changed.answer) {
|
||||
text_1.data = ctx.answer;
|
||||
}
|
||||
},
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
init(this, options);
|
||||
this._state = assign(data(), options.data);
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function createText(data) {
|
||||
return document.createTextNode(data);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function appendNode(node, target) {
|
||||
target.appendChild(node);
|
||||
}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
return Main;
|
||||
}(theAnswer));
|
@ -0,0 +1,13 @@
|
||||
<p>The answer is {answer}</p>
|
||||
|
||||
<script>
|
||||
import answer from 'the-answer';
|
||||
|
||||
export default {
|
||||
data: function () {
|
||||
return {
|
||||
answer: answer
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,174 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
p.textContent = "Hello world!";
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Main;
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWFpbi5qcyIsInNvdXJjZXMiOlsiLi4vc3JjL01haW4uaHRtbCJdLCJzb3VyY2VzQ29udGVudCI6WyI8cD5IZWxsbyB3b3JsZCE8L3A+XG5cbjxzY3JpcHQ+XG5cdGV4cG9ydCBkZWZhdWx0IHtcblx0XHRvbnJlbmRlciAoKSB7XG5cdFx0XHRjb25zb2xlLmxvZyggJ2hlcmUnICk7XG5cdFx0fVxuXHR9O1xuPC9zY3JpcHQ+Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|
@ -0,0 +1 @@
|
||||
svelte compile src/Main.html -m inline -o actual/Main.js
|
@ -0,0 +1,174 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
p.textContent = "Hello world!";
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Main;
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWFpbi5qcyIsInNvdXJjZXMiOlsiLi4vc3JjL01haW4uaHRtbCJdLCJzb3VyY2VzQ29udGVudCI6WyI8cD5IZWxsbyB3b3JsZCE8L3A+XG5cbjxzY3JpcHQ+XG5cdGV4cG9ydCBkZWZhdWx0IHtcblx0XHRvbnJlbmRlciAoKSB7XG5cdFx0XHRjb25zb2xlLmxvZyggJ2hlcmUnICk7XG5cdFx0fVxuXHR9O1xuPC9zY3JpcHQ+Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|
@ -0,0 +1,9 @@
|
||||
<p>Hello world!</p>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
onrender () {
|
||||
console.log( 'here' );
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,174 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
p.textContent = "Hello world!";
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Main;
|
||||
//# sourceMappingURL=Main.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"Main.js","sources":["../src/Main.html"],"sourcesContent":["<p>Hello world!</p>\n\n<script>\n\texport default {\n\t\tonrender () {\n\t\t\tconsole.log( 'here' );\n\t\t}\n\t};\n</script>"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
@ -0,0 +1 @@
|
||||
svelte compile src/Main.html -m -o actual/Main.js
|
@ -0,0 +1,174 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var p;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
p = createElement("p");
|
||||
p.textContent = "Hello world!";
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(p, target, anchor);
|
||||
},
|
||||
|
||||
p: noop,
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(p);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
init(this, options);
|
||||
this._state = assign({}, options.data);
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Main;
|
||||
//# sourceMappingURL=Main.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"Main.js","sources":["../src/Main.html"],"sourcesContent":["<p>Hello world!</p>\n\n<script>\n\texport default {\n\t\tonrender () {\n\t\t\tconsole.log( 'here' );\n\t\t}\n\t};\n</script>"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
@ -0,0 +1,9 @@
|
||||
<p>Hello world!</p>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
onrender () {
|
||||
console.log( 'here' );
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
|
||||
var Main = {};
|
||||
|
||||
Main.filename = "src/Main.html";
|
||||
|
||||
Main.data = function() {
|
||||
return {};
|
||||
};
|
||||
|
||||
Main.render = function(state, options = {}) {
|
||||
var components = new Set();
|
||||
|
||||
function addComponent(component) {
|
||||
components.add(component);
|
||||
}
|
||||
|
||||
var result = { head: '', addComponent };
|
||||
var html = Main._render(result, state, options);
|
||||
|
||||
var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\n');
|
||||
|
||||
return {
|
||||
html,
|
||||
head: result.head,
|
||||
css: { code: cssCode, map: null },
|
||||
toString() {
|
||||
return html;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Main._render = function(__result, ctx, options) {
|
||||
__result.addComponent(Main);
|
||||
|
||||
ctx = Object.assign({}, ctx);
|
||||
|
||||
return `<p>Hello world!</p>`;
|
||||
};
|
||||
|
||||
Main.css = {
|
||||
code: '',
|
||||
map: null
|
||||
};
|
||||
|
||||
var warned = false;
|
||||
|
||||
module.exports = Main;
|
@ -0,0 +1 @@
|
||||
svelte compile --generate ssr src/Main.html > actual/Main.js
|
@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
|
||||
var Main = {};
|
||||
|
||||
Main.filename = "src/Main.html";
|
||||
|
||||
Main.data = function() {
|
||||
return {};
|
||||
};
|
||||
|
||||
Main.render = function(state, options = {}) {
|
||||
var components = new Set();
|
||||
|
||||
function addComponent(component) {
|
||||
components.add(component);
|
||||
}
|
||||
|
||||
var result = { head: '', addComponent };
|
||||
var html = Main._render(result, state, options);
|
||||
|
||||
var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\n');
|
||||
|
||||
return {
|
||||
html,
|
||||
head: result.head,
|
||||
css: { code: cssCode, map: null },
|
||||
toString() {
|
||||
return html;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Main._render = function(__result, ctx, options) {
|
||||
__result.addComponent(Main);
|
||||
|
||||
ctx = Object.assign({}, ctx);
|
||||
|
||||
return `<p>Hello world!</p>`;
|
||||
};
|
||||
|
||||
Main.css = {
|
||||
code: '',
|
||||
map: null
|
||||
};
|
||||
|
||||
var warned = false;
|
||||
|
||||
module.exports = Main;
|
@ -0,0 +1 @@
|
||||
<p>Hello world!</p>
|
@ -0,0 +1,195 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var h1, text, text_1;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
h1 = createElement("h1");
|
||||
text = createText("Hello ");
|
||||
text_1 = createText(ctx.$name);
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(h1, target, anchor);
|
||||
appendNode(text, h1);
|
||||
appendNode(text_1, h1);
|
||||
},
|
||||
|
||||
p: function update(changed, ctx) {
|
||||
if (changed.$name) {
|
||||
text_1.data = ctx.$name;
|
||||
}
|
||||
},
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(h1);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
init(this, options);
|
||||
this._state = assign(this.store._init(["name"]), options.data);
|
||||
this.store._add(this, ["name"]);
|
||||
|
||||
this._handlers.destroy = [removeFromStore];
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function createText(data) {
|
||||
return document.createTextNode(data);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function appendNode(node, target) {
|
||||
target.appendChild(node);
|
||||
}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function removeFromStore() {
|
||||
this.store._remove(this);
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Main;
|
@ -0,0 +1 @@
|
||||
svelte compile src/Main.html --store > actual/Main.js
|
@ -0,0 +1,195 @@
|
||||
/* src/Main.html generated by Svelte v2.3.0 */
|
||||
|
||||
function create_main_fragment(component, ctx) {
|
||||
var h1, text, text_1;
|
||||
|
||||
return {
|
||||
c: function create() {
|
||||
h1 = createElement("h1");
|
||||
text = createText("Hello ");
|
||||
text_1 = createText(ctx.$name);
|
||||
},
|
||||
|
||||
m: function mount(target, anchor) {
|
||||
insertNode(h1, target, anchor);
|
||||
appendNode(text, h1);
|
||||
appendNode(text_1, h1);
|
||||
},
|
||||
|
||||
p: function update(changed, ctx) {
|
||||
if (changed.$name) {
|
||||
text_1.data = ctx.$name;
|
||||
}
|
||||
},
|
||||
|
||||
u: function unmount() {
|
||||
detachNode(h1);
|
||||
},
|
||||
|
||||
d: noop
|
||||
};
|
||||
}
|
||||
|
||||
function Main(options) {
|
||||
init(this, options);
|
||||
this._state = assign(this.store._init(["name"]), options.data);
|
||||
this.store._add(this, ["name"]);
|
||||
|
||||
this._handlers.destroy = [removeFromStore];
|
||||
|
||||
this._fragment = create_main_fragment(this, this._state);
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
this._mount(options.target, options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
assign(Main.prototype, {
|
||||
destroy: destroy,
|
||||
get: get,
|
||||
fire: fire,
|
||||
on: on,
|
||||
set: set,
|
||||
_set: _set,
|
||||
_mount: _mount,
|
||||
_unmount: _unmount,
|
||||
_differs: _differs
|
||||
});
|
||||
|
||||
Main.prototype._recompute = noop;
|
||||
|
||||
function createElement(name) {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
function createText(data) {
|
||||
return document.createTextNode(data);
|
||||
}
|
||||
|
||||
function insertNode(node, target, anchor) {
|
||||
target.insertBefore(node, anchor);
|
||||
}
|
||||
|
||||
function appendNode(node, target) {
|
||||
target.appendChild(node);
|
||||
}
|
||||
|
||||
function detachNode(node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
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 assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
function removeFromStore() {
|
||||
this.store._remove(this);
|
||||
}
|
||||
|
||||
function destroy(detach) {
|
||||
this.destroy = noop;
|
||||
this.fire('destroy');
|
||||
this.set = noop;
|
||||
|
||||
if (detach !== false) this._fragment.u();
|
||||
this._fragment.d();
|
||||
this._fragment = null;
|
||||
this._state = {};
|
||||
}
|
||||
|
||||
function get() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
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 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 _mount(target, anchor) {
|
||||
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
|
||||
}
|
||||
|
||||
function _unmount() {
|
||||
if (this._fragment) this._fragment.u();
|
||||
}
|
||||
|
||||
function _differs(a, b) {
|
||||
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
function callAll(fns) {
|
||||
while (fns && fns.length) fns.shift()();
|
||||
}
|
||||
export default Main;
|
@ -0,0 +1 @@
|
||||
<h1>Hello {$name}</h1>
|
@ -0,0 +1,10 @@
|
||||
const sander = require('sander');
|
||||
|
||||
process.chdir(__dirname);
|
||||
|
||||
sander.readdirSync('samples').forEach(dir => {
|
||||
if (dir[0] === '.') return;
|
||||
|
||||
sander.rimrafSync(`samples/${dir}/expected`);
|
||||
sander.copydirSync(`samples/${dir}/actual`).to(`samples/${dir}/expected`);
|
||||
});
|
@ -1,11 +1,11 @@
|
||||
const glob = require("glob");
|
||||
const glob = require("tiny-glob/sync.js");
|
||||
|
||||
require("./setup");
|
||||
|
||||
glob.sync("**/__test__.js", { cwd: "src" }).forEach(function(file) {
|
||||
glob("**/__test__.js", { cwd: "src" }).forEach(function(file) {
|
||||
require("../src/" + file);
|
||||
});
|
||||
|
||||
glob.sync("*/index.js", { cwd: "test" }).forEach(function(file) {
|
||||
glob("*/index.js", { cwd: "test" }).forEach(function(file) {
|
||||
require("./" + file);
|
||||
});
|
||||
|
Loading…
Reference in new issue