Skip to content

Commit

Permalink
feat: make array mutations re-renders work for el and scope variables
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenrui committed Mar 20, 2024
1 parent f7ef980 commit 7e03b93
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
17 changes: 16 additions & 1 deletion lib/entity/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,22 @@ export class Events {
const state = this.entity.base.state
engine._arrayVariables.forEach((variable) => {
if (!this.entity.data.variables.includes(variable)) return
state.evaluateDependencies(variable)

if (State.isElState(variable) || State.isScopeState(variable)) {
const [type, object] = variable.split('.')

if (!object) return

if (type === State.EL_STATE) {
const varName = `${this.entity.id}.${object}`
state.evaluateDependencies(varName)
} else if (type === State.SCOPE_STATE) {
if (!this.entity.scope) return
const varName = `${this.entity.scope.id}.${object}`
state.evaluateDependencies(varName)
}
} else
state.evaluateDependencies(variable)
})
}

Expand Down
13 changes: 10 additions & 3 deletions lib/generators/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,18 @@ export class Lexer {
const hasMutateArrayMethods = MiniArray.mutateMethods.some((method) =>
properties.includes(method)
)

const isEntityVariable = Lexer.ENTITY_KEYS.some((key) => object.startsWith(key))

if (hasMutateArrayMethods)
this._arrayVariables.push(object)

if (object.length && Lexer.ENTITY_KEYS.includes(object)) {
{
if (isEntityVariable)
this._arrayVariables.push([object, properties[0]].join('.'))
else
this._arrayVariables.push(object)
}

if (object.length && isEntityVariable) {
this._identifiers.push(object)
this._identifiers.push([object, properties[0]].join('.'))
}
Expand Down

0 comments on commit 7e03b93

Please sign in to comment.