Add store data to bindings

pull/3534/head
Bryan Terce 5 years ago
parent 2ab77e249b
commit 0a4caeb7e9
No known key found for this signature in database
GPG Key ID: DF2E2829CA6E5BF4

@ -10,7 +10,7 @@ export interface BlockOptions {
renderer?: Renderer;
comment?: string;
key?: string;
bindings?: Map<string, { object: string; property: string; snippet: string }>;
bindings?: Map<string, { object: string; property: string; snippet: string; store: string; tail: string }>;
dependencies?: Set<string>;
}
@ -27,7 +27,7 @@ export default class Block {
dependencies: Set<string>;
bindings: Map<string, { object: string; property: string; snippet: string }>;
bindings: Map<string, { object: string; property: string; snippet: string; store: string; tail: string }>;
builders: {
init: CodeBuilder;

@ -121,11 +121,15 @@ export default class EachBlockWrapper extends Wrapper {
view_length: fixed_length === null ? `${iterations}.[✂${c}-${c+4}✂]` : fixed_length
};
const store = node.expression.node.name[0] === '$' ? node.expression.node.name.slice(1) : null;
node.contexts.forEach(prop => {
this.block.bindings.set(prop.key.name, {
object: this.vars.each_block_value,
property: this.index_name,
snippet: attach_head(`${this.vars.each_block_value}[${this.index_name}]`, prop.tail)
snippet: attach_head(`${this.vars.each_block_value}[${this.index_name}]`, prop.tail),
store,
tail: attach_head(`[${this.index_name}]`, prop.tail)
});
});

@ -249,7 +249,7 @@ function get_event_handler(
snippet?: string;
} {
const value = get_value_from_dom(renderer, binding.parent, binding);
const store = binding.object[0] === '$' ? binding.object.slice(1) : null;
let store = binding.object[0] === '$' ? binding.object.slice(1) : null;
let tail = '';
if (binding.node.expression.node.type === 'MemberExpression') {
@ -258,7 +258,13 @@ function get_event_handler(
}
if (binding.node.is_contextual) {
const { object, property, snippet } = block.bindings.get(name);
const binding = block.bindings.get(name);
const { object, property, snippet } = binding;
if (binding.store) {
store = store || binding.store;
tail = `${binding.tail}${tail}`;
}
return {
uses_context: true,

Loading…
Cancel
Save