component spread

pull/1367/head
Rich Harris 7 years ago
parent 2c7d935162
commit b843e82990

@ -44,7 +44,7 @@ export default class Component extends Node {
info.attributes.forEach(node => { info.attributes.forEach(node => {
switch (node.type) { switch (node.type) {
case 'Attribute': case 'Attribute':
// TODO spread case 'Spread':
this.attributes.push(new Attribute(compiler, this, scope, node)); this.attributes.push(new Attribute(compiler, this, scope, node));
break; break;
@ -150,7 +150,7 @@ export default class Component extends Node {
const updates: string[] = []; const updates: string[] = [];
const usesSpread = !!this.attributes.find(a => a.spread); const usesSpread = !!this.attributes.find(a => a.isSpread);
const attributeObject = usesSpread const attributeObject = usesSpread
? '{}' ? '{}'
@ -174,21 +174,20 @@ export default class Component extends Node {
const initialProps = []; const initialProps = [];
const changes = []; const changes = [];
this.attributes this.attributes.forEach(attr => {
.forEach(attr => { const { name, dependencies } = attr;
const { spread, name, dependencies } = attr;
const value = attr.getValue();
const condition = dependencies.size > 0 const condition = dependencies.size > 0
? [...dependencies].map(d => `changed.${d}`).join(' || ') ? [...dependencies].map(d => `changed.${d}`).join(' || ')
: null; : null;
if (spread) { if (attr.isSpread) {
const value = attr.expression.snippet;
initialProps.push(value); initialProps.push(value);
changes.push(condition ? `${condition} && ${value}` : value); changes.push(condition ? `${condition} && ${value}` : value);
} else { } else {
const obj = `{ ${quoteIfNecessary(name)}: ${value} }`; const obj = `{ ${quoteIfNecessary(name)}: ${attr.getValue()} }`;
initialProps.push(obj); initialProps.push(obj);
changes.push(condition ? `${condition} && ${obj}` : obj); changes.push(condition ? `${condition} && ${obj}` : obj);

Loading…
Cancel
Save