mirror of https://github.com/sveltejs/svelte
parent
f4bee21793
commit
ba5c3ce574
@ -0,0 +1,32 @@
|
||||
export function nodes_match(a, b) {
|
||||
if (!!a !== !!b) return false;
|
||||
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
||||
|
||||
if (a && typeof a === 'object') {
|
||||
if (Array.isArray(a)) {
|
||||
if (a.length !== b.length) return false;
|
||||
return a.every((child, i) => nodes_match(child, b[i]));
|
||||
}
|
||||
|
||||
const a_keys = Object.keys(a).sort();
|
||||
const b_keys = Object.keys(b).sort();
|
||||
|
||||
if (a_keys.length !== b_keys.length) return false;
|
||||
|
||||
let i = a_keys.length;
|
||||
while (i--) {
|
||||
const key = a_keys[i];
|
||||
if (b_keys[i] !== key) return false;
|
||||
|
||||
if (key === 'start' || key === 'end') continue;
|
||||
|
||||
if (!nodes_match(a[key], b[key])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return a === b;
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/* generated by Svelte vX.Y.Z */
|
||||
import { SvelteComponent as SvelteComponent_1, addListener, append, createElement, createText, detachNode, init, insert, run, safe_not_equal, setData } from "svelte/internal.js";
|
||||
|
||||
function create_fragment(component, ctx) {
|
||||
var button, text1, p, text2, text3_value = ctx.things.length, text3, current, dispose;
|
||||
|
||||
return {
|
||||
c() {
|
||||
button = createElement("button");
|
||||
button.textContent = "foo";
|
||||
text1 = createText("\n\n");
|
||||
p = createElement("p");
|
||||
text2 = createText("number of things: ");
|
||||
text3 = createText(text3_value);
|
||||
dispose = addListener(button, "click", ctx.foo);
|
||||
},
|
||||
|
||||
m(target, anchor) {
|
||||
insert(target, button, anchor);
|
||||
insert(target, text1, anchor);
|
||||
insert(target, p, anchor);
|
||||
append(p, text2);
|
||||
append(p, text3);
|
||||
current = true;
|
||||
},
|
||||
|
||||
p(changed, ctx) {
|
||||
if ((changed.things) && text3_value !== (text3_value = ctx.things.length)) {
|
||||
setData(text3, text3_value);
|
||||
}
|
||||
},
|
||||
|
||||
i(target, anchor) {
|
||||
if (current) return;
|
||||
this.m(target, anchor);
|
||||
},
|
||||
|
||||
o: run,
|
||||
|
||||
d(detach) {
|
||||
if (detach) {
|
||||
detachNode(button);
|
||||
detachNode(text1);
|
||||
detachNode(p);
|
||||
}
|
||||
|
||||
dispose();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function define($$self, $$props, $$make_dirty) {
|
||||
let things = [];
|
||||
|
||||
function foo() {
|
||||
things.push(1);
|
||||
$$make_dirty('things');
|
||||
}
|
||||
|
||||
$$self.$$.get = () => ({ things, foo });
|
||||
}
|
||||
|
||||
class SvelteComponent extends SvelteComponent_1 {
|
||||
constructor(options) {
|
||||
super();
|
||||
init(this, options, define, create_fragment, safe_not_equal);
|
||||
}
|
||||
}
|
||||
|
||||
export default SvelteComponent;
|
@ -0,0 +1,12 @@
|
||||
<script>
|
||||
let things = [];
|
||||
|
||||
function foo() {
|
||||
things.push(1);
|
||||
things = things;
|
||||
}
|
||||
</script>
|
||||
|
||||
<button on:click={foo}>foo</button>
|
||||
|
||||
<p>number of things: {things.length}</p>
|
Loading…
Reference in new issue