rename changed to dirty, for more internal consistency

pull/3945/head
Rich Harris 6 years ago
parent fb732e5b5b
commit 9659602d4f

@ -209,7 +209,6 @@ export default class Component {
});
const subscribable_name = name.slice(1);
// this.add_reference(subscribable_name);
const variable = this.var_lookup.get(subscribable_name);
if (variable) variable.subscribable = true;

@ -301,12 +301,12 @@ export default class Block {
} else {
const ctx = this.maintain_context ? x`#new_ctx` : x`#ctx`;
let changed: Identifier | ArrayPattern = { type: 'Identifier', name: '#changed' };
let dirty: Identifier | ArrayPattern = { type: 'Identifier', name: '#dirty' };
if (!this.renderer.context_overflow && !this.parent) {
changed = { type: 'ArrayPattern', elements: [changed] };
dirty = { type: 'ArrayPattern', elements: [dirty] };
}
properties.update = x`function #update(${ctx}, ${changed}) {
properties.update = x`function #update(${ctx}, ${dirty}) {
${this.maintain_context && b`#ctx = ${ctx};`}
${this.chunks.update}
}`;

@ -192,12 +192,12 @@ export default class Renderer {
.reduce((lhs, rhs) => x`${lhs}, ${rhs}}`);
}
changed(names, is_reactive_declaration = false): Expression {
dirty(names, is_reactive_declaration = false): Expression {
const renderer = this;
const changed = (is_reactive_declaration
const dirty = (is_reactive_declaration
? x`$$self.$$.dirty`
: x`#changed`) as Identifier | MemberExpression;
: x`#dirty`) as Identifier | MemberExpression;
const get_bitmask = () => names.reduce((bits, name) => {
const member = renderer.context_lookup.get(name);
@ -225,7 +225,9 @@ export default class Renderer {
get type() {
// we make the type a getter, even though it's always
// a BinaryExpression, because it gives us an opportunity
// to lazily create the node
// to lazily create the node. TODO would be better if
// context was determined before rendering, so that
// this indirection was unnecessary
const bitmask = get_bitmask();
@ -233,12 +235,12 @@ export default class Renderer {
const expression = bitmask
.map((bits, i) => ({ bits, i }))
.filter(({ bits }) => bits)
.map(({ bits, i }) => x`${changed}[${i}] & ${bits}`)
.map(({ bits, i }) => x`${dirty}[${i}] & ${bits}`)
.reduce((lhs, rhs) => x`${lhs} || ${rhs}`);
({ operator, left, right } = expression);
} else {
({ operator, left, right } = x`${changed} & ${bitmask[0] || 0}` as BinaryExpression); // TODO the `|| 0` case should never apply
({ operator, left, right } = x`${dirty} & ${bitmask[0] || 0}` as BinaryExpression); // TODO the `|| 0` case should never apply
}
return 'BinaryExpression';

@ -279,14 +279,6 @@ export default function dom(
}
const initial_context = renderer.context.slice(0, i + 1);
// const initial_context = renderer.context.filter(member => {
// // return member.variable
// // ? (member.variable.referenced || member.variable.export_name)
// // : !member.is_contextual;
// return member.variable || !member.is_contextual;
// });
const has_definition = (
(instance_javascript && instance_javascript.length > 0) ||
filtered_props.length > 0 ||
@ -330,7 +322,7 @@ export default function dom(
return variable && (variable.export_name || variable.mutated || variable.reassigned);
});
const condition = !uses_props && writable.length > 0 && renderer.changed(writable, true);
const condition = !uses_props && writable.length > 0 && renderer.dirty(writable, true);
let statement = d.node; // TODO remove label (use d.node.body) if it's not referenced

@ -192,7 +192,7 @@ export default class AwaitBlockWrapper extends Wrapper {
if (dependencies.length > 0) {
const condition = x`
${block.renderer.changed(dependencies)} &&
${block.renderer.dirty(dependencies)} &&
${promise} !== (${promise} = ${snippet}) &&
@handle_promise(${promise}, ${info})`;
@ -207,7 +207,7 @@ export default class AwaitBlockWrapper extends Wrapper {
} else {
const #child_ctx = #ctx.slice();
#child_ctx[${value_index}] = ${info}.resolved;
${info}.block.p(#child_ctx, #changed);
${info}.block.p(#child_ctx, #dirty);
}
`);
} else {
@ -221,7 +221,7 @@ export default class AwaitBlockWrapper extends Wrapper {
{
const #child_ctx = #ctx.slice();
#child_ctx[${value_index}] = ${info}.resolved;
${info}.block.p(#child_ctx, #changed);
${info}.block.p(#child_ctx, #dirty);
}
`);
}

@ -69,7 +69,7 @@ export default class DebugTagWrapper extends Wrapper {
debugger;`;
if (dependencies.size) {
const condition = renderer.changed(Array.from(dependencies));
const condition = renderer.dirty(Array.from(dependencies));
block.chunks.update.push(b`
if (${condition}) {

@ -277,7 +277,7 @@ export default class EachBlockWrapper extends Wrapper {
if (this.else.block.has_update_method) {
block.chunks.update.push(b`
if (!${this.vars.data_length} && ${each_block_else}) {
${each_block_else}.p(#ctx, #changed);
${each_block_else}.p(#ctx, #dirty);
} else if (!${this.vars.data_length}) {
${each_block_else} = ${this.else.block.name}(#ctx);
${each_block_else}.c();
@ -403,7 +403,7 @@ export default class EachBlockWrapper extends Wrapper {
${this.block.has_outros && b`@group_outros();`}
${this.node.has_animation && b`for (let #i = 0; #i < ${view_length}; #i += 1) ${iterations}[#i].r();`}
${iterations} = @update_keyed_each(${iterations}, #changed, ${get_key}, ${dynamic ? 1 : 0}, #ctx, ${this.vars.each_block_value}, ${lookup}, ${update_mount_node}, ${destroy}, ${create_each_block}, ${update_anchor_node}, ${this.vars.get_each_context});
${iterations} = @update_keyed_each(${iterations}, #dirty, ${get_key}, ${dynamic ? 1 : 0}, #ctx, ${this.vars.each_block_value}, ${lookup}, ${update_mount_node}, ${destroy}, ${create_each_block}, ${update_anchor_node}, ${this.vars.get_each_context});
${this.node.has_animation && b`for (let #i = 0; #i < ${view_length}; #i += 1) ${iterations}[#i].a();`}
${this.block.has_outros && b`@check_outros();`}
`);
@ -487,7 +487,7 @@ export default class EachBlockWrapper extends Wrapper {
const for_loop_body = this.block.has_update_method
? b`
if (${iterations}[#i]) {
${iterations}[#i].p(child_ctx, #changed);
${iterations}[#i].p(child_ctx, #dirty);
${has_transitions && b`@transition_in(${this.vars.iterations}[#i], 1);`}
} else {
${iterations}[#i] = ${create_each_block}(child_ctx);
@ -560,7 +560,7 @@ export default class EachBlockWrapper extends Wrapper {
`;
block.chunks.update.push(b`
if (${block.renderer.changed(Array.from(all_dependencies))}) {
if (${block.renderer.dirty(Array.from(all_dependencies))}) {
${update}
}
`);

@ -139,7 +139,7 @@ export default class AttributeWrapper {
}
if (dependencies.length > 0) {
let condition = block.renderer.changed(dependencies);
let condition = block.renderer.dirty(dependencies);
if (should_cache) {
condition = is_src

@ -90,7 +90,7 @@ export default class BindingWrapper {
const dependency_array = [...this.node.expression.dependencies];
if (dependency_array.length > 0) {
update_conditions.push(block.renderer.changed(dependency_array));
update_conditions.push(block.renderer.dirty(dependency_array));
}
if (parent.node.name === 'input') {

@ -45,7 +45,7 @@ export default class StyleAttributeWrapper extends AttributeWrapper {
// }
if (prop_dependencies.size) {
let condition = block.renderer.changed(Array.from(prop_dependencies));
let condition = block.renderer.dirty(Array.from(prop_dependencies));
if (block.has_outros) {
condition = x`!#current || ${condition}`;

@ -624,7 +624,7 @@ export default class ElementWrapper extends Wrapper {
this.attributes
.forEach(attr => {
const condition = attr.node.dependencies.size > 0
? block.renderer.changed(Array.from(attr.node.dependencies))
? block.renderer.dirty(Array.from(attr.node.dependencies))
: null;
if (attr.node.is_spread) {
@ -857,7 +857,7 @@ export default class ElementWrapper extends Wrapper {
block.chunks.update.push(updater);
} else if ((dependencies && dependencies.size > 0) || this.class_dependencies.length) {
const all_dependencies = this.class_dependencies.concat(...dependencies);
const condition = block.renderer.changed(all_dependencies);
const condition = block.renderer.dirty(all_dependencies);
block.chunks.update.push(b`
if (${condition}) {

@ -266,12 +266,12 @@ export default class IfBlockWrapper extends Wrapper {
/* eslint-disable @typescript-eslint/indent,indent */
if (this.needs_update) {
block.chunks.init.push(b`
function ${select_block_type}(#ctx, #changed) {
function ${select_block_type}(#ctx, #dirty) {
${this.branches.map(({ dependencies, condition, snippet, block }) => condition
? b`
${snippet && (
dependencies.length > 0
? b`if (${condition} == null || ${block.renderer.changed(dependencies)}) ${condition} = !!${snippet}`
? b`if (${condition} == null || ${block.renderer.dirty(dependencies)}) ${condition} = !!${snippet}`
: b`if (${condition} == null) ${condition} = !!${snippet}`
)}
if (${condition}) return ${block.name};`
@ -280,7 +280,7 @@ export default class IfBlockWrapper extends Wrapper {
`);
} else {
block.chunks.init.push(b`
function ${select_block_type}(#ctx, #changed) {
function ${select_block_type}(#ctx, #dirty) {
${this.branches.map(({ condition, snippet, block }) => condition
? b`if (${snippet || condition}) return ${block.name};`
: b`return ${block.name};`)}
@ -322,21 +322,21 @@ export default class IfBlockWrapper extends Wrapper {
if (dynamic) {
block.chunks.update.push(b`
if (${current_block_type} === (${current_block_type} = ${select_block_type}(#ctx, #changed)) && ${name}) {
${name}.p(#ctx, #changed);
if (${current_block_type} === (${current_block_type} = ${select_block_type}(#ctx, #dirty)) && ${name}) {
${name}.p(#ctx, #dirty);
} else {
${change_block}
}
`);
} else {
block.chunks.update.push(b`
if (${current_block_type} !== (${current_block_type} = ${select_block_type}(#ctx, #changed))) {
if (${current_block_type} !== (${current_block_type} = ${select_block_type}(#ctx, #dirty))) {
${change_block}
}
`);
}
} else if (dynamic) {
block.chunks.update.push(b`${name}.p(#ctx, #changed);`);
block.chunks.update.push(b`${name}.p(#ctx, #dirty);`);
}
if (if_exists_condition) {
@ -385,12 +385,12 @@ export default class IfBlockWrapper extends Wrapper {
${this.needs_update
? b`
function ${select_block_type}(#ctx, #changed) {
function ${select_block_type}(#ctx, #dirty) {
${this.branches.map(({ dependencies, condition, snippet }, i) => condition
? b`
${snippet && (
dependencies.length > 0
? b`if (${block.renderer.changed(dependencies)}) ${condition} = !!${snippet}`
? b`if (${block.renderer.dirty(dependencies)}) ${condition} = !!${snippet}`
: b`if (${condition} == -1) ${condition} = !!${snippet}`
)}
if (${condition}) return ${i};`
@ -399,7 +399,7 @@ export default class IfBlockWrapper extends Wrapper {
}
`
: b`
function ${select_block_type}(#ctx, #changed) {
function ${select_block_type}(#ctx, #dirty) {
${this.branches.map(({ condition, snippet }, i) => condition
? b`if (${snippet || condition}) return ${i};`
: b`return ${i};`)}
@ -473,9 +473,9 @@ export default class IfBlockWrapper extends Wrapper {
if (dynamic) {
block.chunks.update.push(b`
let ${previous_block_index} = ${current_block_type_index};
${current_block_type_index} = ${select_block_type}(#ctx, #changed);
${current_block_type_index} = ${select_block_type}(#ctx, #dirty);
if (${current_block_type_index} === ${previous_block_index}) {
${if_current_block_type_index(b`${if_blocks}[${current_block_type_index}].p(#ctx, #changed);`)}
${if_current_block_type_index(b`${if_blocks}[${current_block_type_index}].p(#ctx, #dirty);`)}
} else {
${change_block}
}
@ -483,14 +483,14 @@ export default class IfBlockWrapper extends Wrapper {
} else {
block.chunks.update.push(b`
let ${previous_block_index} = ${current_block_type_index};
${current_block_type_index} = ${select_block_type}(#ctx, #changed);
${current_block_type_index} = ${select_block_type}(#ctx, #dirty);
if (${current_block_type_index} !== ${previous_block_index}) {
${change_block}
}
`);
}
} else if (dynamic) {
block.chunks.update.push(b`${name}.p(#ctx, #changed);`);
block.chunks.update.push(b`${name}.p(#ctx, #dirty);`);
}
block.chunks.destroy.push(
@ -527,7 +527,7 @@ export default class IfBlockWrapper extends Wrapper {
const enter = dynamic
? b`
if (${name}) {
${name}.p(#ctx, #changed);
${name}.p(#ctx, #dirty);
${has_transitions && b`@transition_in(${name}, 1);`}
} else {
${name} = ${branch.block.name}(#ctx);
@ -548,7 +548,7 @@ export default class IfBlockWrapper extends Wrapper {
`;
if (branch.snippet) {
block.chunks.update.push(b`if (${block.renderer.changed(branch.dependencies)}) ${branch.condition} = ${branch.snippet}`);
block.chunks.update.push(b`if (${block.renderer.dirty(branch.dependencies)}) ${branch.condition} = ${branch.snippet}`);
}
// no `p()` here — we don't want to update outroing nodes,
@ -577,7 +577,7 @@ export default class IfBlockWrapper extends Wrapper {
}
} else if (dynamic) {
block.chunks.update.push(b`
if (${branch.condition}) ${name}.p(#ctx, #changed);
if (${branch.condition}) ${name}.p(#ctx, #dirty);
`);
}

@ -207,7 +207,7 @@ export default class InlineComponentWrapper extends Wrapper {
const { name, dependencies } = attr;
const condition = dependencies.size > 0 && (dependencies.size !== all_dependencies.size)
? renderer.changed(Array.from(dependencies))
? renderer.dirty(Array.from(dependencies))
: null;
if (attr.is_spread) {
@ -240,7 +240,7 @@ export default class InlineComponentWrapper extends Wrapper {
`);
if (all_dependencies.size) {
const condition = renderer.changed(Array.from(all_dependencies));
const condition = renderer.dirty(Array.from(all_dependencies));
updates.push(b`
const ${name_changes} = ${condition} ? @get_spread_update(${levels}, [
@ -256,7 +256,7 @@ export default class InlineComponentWrapper extends Wrapper {
dynamic_attributes.forEach((attribute: Attribute) => {
const dependencies = attribute.get_dependencies();
if (dependencies.length > 0) {
const condition = renderer.changed(dependencies);
const condition = renderer.dirty(dependencies);
updates.push(b`
if (${condition}) ${name_changes}.${attribute.name} = ${attribute.get_value(block)};
@ -268,8 +268,8 @@ export default class InlineComponentWrapper extends Wrapper {
if (non_let_dependencies.length > 0) {
updates.push(b`
if (${renderer.changed(non_let_dependencies)}) {
${name_changes}.$$scope = { changed: #changed, ctx: #ctx };
if (${renderer.dirty(non_let_dependencies)}) {
${name_changes}.$$scope = { dirty: #dirty, ctx: #ctx };
}`);
}
@ -296,7 +296,7 @@ export default class InlineComponentWrapper extends Wrapper {
);
updates.push(b`
if (!${updating} && ${renderer.changed(Array.from(binding.expression.dependencies))}) {
if (!${updating} && ${renderer.dirty(Array.from(binding.expression.dependencies))}) {
${updating} = true;
${name_changes}.${binding.name} = ${snippet};
@add_flush_callback(() => ${updating} = false);

@ -119,12 +119,12 @@ export default class SlotWrapper extends Wrapper {
});
if (dynamic_dependencies.length > 0) {
changes.properties.push(p`${attribute.name}: ${renderer.changed(dynamic_dependencies)}`);
changes.properties.push(p`${attribute.name}: ${renderer.dirty(dynamic_dependencies)}`);
}
});
renderer.blocks.push(b`
const ${get_slot_changes_fn} = #changed => ${changes};
const ${get_slot_changes_fn} = #dirty => ${changes};
const ${get_slot_context_fn} = #ctx => ${get_slot_data(block, this.node.values)};
`);
} else {
@ -202,10 +202,10 @@ export default class SlotWrapper extends Wrapper {
});
block.chunks.update.push(b`
if (${slot} && ${slot}.p && ${renderer.changed(dynamic_dependencies)}) {
if (${slot} && ${slot}.p && ${renderer.dirty(dynamic_dependencies)}) {
${slot}.p(
@get_slot_context(${slot_definition}, #ctx, ${renderer.reference('$$scope')}, ${get_slot_context_fn}),
@get_slot_changes(${slot_definition}, ${renderer.reference('$$scope')}, #changed, ${get_slot_changes_fn})
@get_slot_changes(${slot_definition}, ${renderer.reference('$$scope')}, #dirty, ${get_slot_changes_fn})
);
}
`);

@ -75,7 +75,7 @@ export default class TitleWrapper extends Wrapper {
if (all_dependencies.size) {
const dependencies = Array.from(all_dependencies);
let condition = block.renderer.changed(dependencies);
let condition = block.renderer.dirty(dependencies);
if (block.has_outros) {
condition = x`!#current || ${condition}`;

@ -139,7 +139,7 @@ export default class WindowWrapper extends Wrapper {
// special case... might need to abstract this out if we add more special cases
if (bindings.scrollX || bindings.scrollY) {
const condition = renderer.changed([bindings.scrollX, bindings.scrollY].filter(Boolean));
const condition = renderer.dirty([bindings.scrollX, bindings.scrollY].filter(Boolean));
const scrollX = bindings.scrollX ? renderer.reference(bindings.scrollX) : x`@_window.pageXOffset`;
const scrollY = bindings.scrollY ? renderer.reference(bindings.scrollY) : x`@_window.pageYOffset`;

@ -39,7 +39,7 @@ export default class Tag extends Wrapper {
if (this.node.should_cache) block.add_variable(value, snippet); // TODO may need to coerce snippet to string
if (dependencies.length > 0) {
let condition = block.renderer.changed(dependencies);
let condition = block.renderer.dirty(dependencies);
if (block.has_outros) {
condition = x`!#current || ${condition}`;

@ -33,7 +33,7 @@ export default function add_actions(
let condition = x`@is_function(${id}.update)`;
if (dependencies.length > 0) {
condition = x`${condition} && ${block.renderer.changed(dependencies)}`;
condition = x`${condition} && ${block.renderer.dirty(dependencies)}`;
}
block.chunks.update.push(

@ -11,7 +11,7 @@ interface Fragment {
/* claim */ l: (nodes: any) => void;
/* hydrate */ h: () => void;
/* mount */ m: (target: HTMLElement, anchor: any) => void;
/* update */ p: (changed: any, ctx: any) => void;
/* update */ p: (ctx: any, dirty: any) => void;
/* measure */ r: () => void;
/* fix */ f: () => void;
/* animate */ a: () => void;

@ -21,7 +21,7 @@ export function fix_and_outro_and_destroy_block(block, lookup) {
outro_and_destroy_block(block, lookup);
}
export function update_keyed_each(old_blocks, changed, get_key, dynamic, ctx, list, lookup, node, destroy, create_each_block, next, get_context) {
export function update_keyed_each(old_blocks, dirty, get_key, dynamic, ctx, list, lookup, node, destroy, create_each_block, next, get_context) {
let o = old_blocks.length;
let n = list.length;
@ -43,7 +43,7 @@ export function update_keyed_each(old_blocks, changed, get_key, dynamic, ctx, li
block = create_each_block(key, child_ctx);
block.c();
} else if (dynamic) {
block.p(child_ctx, changed);
block.p(child_ctx, dirty);
}
new_lookup.set(key, new_blocks[i] = block);

@ -76,10 +76,10 @@ export function get_slot_context(definition, ctx, $$scope, fn) {
: $$scope.ctx;
}
export function get_slot_changes(definition, $$scope, changed, fn) {
export function get_slot_changes(definition, $$scope, dirty, fn) {
return definition[2] && fn
? $$scope.changed | definition[2](fn(changed))
: $$scope.changed;
? $$scope.dirty | definition[2](fn(dirty))
: $$scope.dirty;
}
export function exclude_internal_props(props) {

Loading…
Cancel
Save