wechat-miniprogram / glass-easel

Multiple-backend component-based JavaScript framework
MIT License
243 stars 34 forks source link

Literal values in template always treated as updated #141

Closed SgLy closed 3 months ago

SgLy commented 8 months ago

Literal values in template like arr-prop in <component arr-prop="{{ [valueA, valueB] }}"> are always treated as updated, regardless of whether valueA and valueB are updated or not. This may lead to unrelated data updates triggering property observers.

Maybe better to let a literal value stay not updated when all its member is not updated?

LastLeaf commented 3 months ago

The core problem is that sometimes we pass update path tree like { a: undefined } or [undefined, undefined] as a dynamic property value. Currently we treat them as updated, which is inaccurate.

We have two approaches to solve this problem.

  1. Have a check when assigning this kind of update path tree to a property. This requires a check on every replaceProperty calls. This might be costy when the update path tree is large.
  2. Have a check before generating this kind of update path tree. This requires a check on every literal object and array in templates. This might be costy when literals are heavily used.
LastLeaf commented 3 months ago

The approach 1 cannot solve this case {{ 'xxx' + { f: a } }} , so it is not perfect. Approach 2 is preferred.