|
|
|
@ -19,8 +19,6 @@ export interface BlockOptions {
|
|
|
|
|
changeableIndexes?: Map<string, boolean>;
|
|
|
|
|
indexNames?: Map<string, string>;
|
|
|
|
|
listNames?: Map<string, string>;
|
|
|
|
|
indexName?: string;
|
|
|
|
|
listName?: string;
|
|
|
|
|
dependencies?: Set<string>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -42,9 +40,6 @@ export default class Block {
|
|
|
|
|
dependencies: Set<string>;
|
|
|
|
|
indexNames: Map<string, string>;
|
|
|
|
|
listNames: Map<string, string>;
|
|
|
|
|
indexName: string;
|
|
|
|
|
listName: string;
|
|
|
|
|
listAlias: string;
|
|
|
|
|
|
|
|
|
|
builders: {
|
|
|
|
|
init: CodeBuilder;
|
|
|
|
@ -92,9 +87,6 @@ export default class Block {
|
|
|
|
|
this.indexNames = options.indexNames;
|
|
|
|
|
this.listNames = options.listNames;
|
|
|
|
|
|
|
|
|
|
this.indexName = options.indexName;
|
|
|
|
|
this.listName = options.listName;
|
|
|
|
|
|
|
|
|
|
this.builders = {
|
|
|
|
|
init: new CodeBuilder(),
|
|
|
|
|
create: new CodeBuilder(),
|
|
|
|
@ -121,8 +113,6 @@ export default class Block {
|
|
|
|
|
.set('state', this.getUniqueName('state'));
|
|
|
|
|
if (this.key) this.aliases.set('key', this.getUniqueName('key'));
|
|
|
|
|
|
|
|
|
|
this.listAlias = this.getUniqueName(this.listName);
|
|
|
|
|
|
|
|
|
|
this.hasUpdateMethod = false; // determined later
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -198,23 +188,17 @@ export default class Block {
|
|
|
|
|
|
|
|
|
|
// TODO `this.contexts` is possibly redundant post-#1122
|
|
|
|
|
const initializers = [];
|
|
|
|
|
const updaters = [];
|
|
|
|
|
this.contexts.forEach((alias, name) => {
|
|
|
|
|
// TODO only the ones that are actually used in this block...
|
|
|
|
|
const assignment = `${alias} = state.${name}`;
|
|
|
|
|
|
|
|
|
|
initializers.push(assignment);
|
|
|
|
|
updaters.push(`${assignment};`);
|
|
|
|
|
|
|
|
|
|
this.hasUpdateMethod = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.indexNames.forEach((alias, name) => {
|
|
|
|
|
this.contexts.forEach((name, context) => {
|
|
|
|
|
// TODO only the ones that are actually used in this block...
|
|
|
|
|
const assignment = `${alias} = state.${alias}`; // TODO this is wrong!!!
|
|
|
|
|
const listName = this.listNames.get(context);
|
|
|
|
|
const indexName = this.indexNames.get(context);
|
|
|
|
|
|
|
|
|
|
initializers.push(assignment);
|
|
|
|
|
updaters.push(`${assignment};`);
|
|
|
|
|
initializers.push(
|
|
|
|
|
`${name} = state.${context}`,
|
|
|
|
|
`${listName} = state.${listName}`,
|
|
|
|
|
`${indexName} = state.${indexName}`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
this.hasUpdateMethod = true;
|
|
|
|
|
});
|
|
|
|
@ -278,12 +262,12 @@ export default class Block {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.hasUpdateMethod) {
|
|
|
|
|
if (this.builders.update.isEmpty() && updaters.length === 0) {
|
|
|
|
|
if (this.builders.update.isEmpty() && initializers.length === 0) {
|
|
|
|
|
properties.addBlock(`p: @noop,`);
|
|
|
|
|
} else {
|
|
|
|
|
properties.addBlock(deindent`
|
|
|
|
|
p: function update(changed, state) {
|
|
|
|
|
${updaters}
|
|
|
|
|
${initializers.map(str => `${str};`)}
|
|
|
|
|
${this.builders.update}
|
|
|
|
|
},
|
|
|
|
|
`);
|
|
|
|
|