[CONTEXT]: provided values are handed over on connect only, consumers do not follow later provider updates

未关闭
#175 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
活跃
技术栈
javascript
领域
frontend

调研方向

Read BaseElement.update() and verifyProvidedProperties() to assess the proposed update hook and its subtree walk; compare the behavior with the context example in examples/showcase/ and the current context documentation. The issue needs a maintainer decision between documenting connect-time values and updating consumers after provider changes; done means that decision is reflected consistently in the implementation or docs, showcase, and treatment of manual requestContext() callbacks.

由索引模型根据 Issue 内容生成。

描述

question

Observation

A provider lists a plain value in provideProperties():

class Provider extends TemplateElement {
    properties() {
        return { theme: 'light' };
    }
    provideProperties() {
        return { theme: this.theme };
    }
}

class Consumer extends TemplateElement {
    injectProperties() {
        return { theme: '' };
    }
}

The consumer gets light when it connects. When the provider sets this.theme = 'dark' later, the consumer keeps light. A Store in provideProperties() behaves differently: it is handed over by reference, the consumer subscribes to it, so changes in the store render the consumer.

The context section of examples/showcase/ (#171) shows both behaviours side by side.

Cause

verifyProvidedProperties() replays missed requests and compares customChild[key] !== providedProperties[key], but it only runs in connectedCallback() (both branches). Nothing runs it after a provider update.

Options

  1. Document it: a provided value is handed over when the consumer connects, values that change are provided as a Store. No code.
  2. Run this.verifyProvidedProperties() at the end of BaseElement.update(). Three lines, consumers then follow every provided value. Costs a subtree walk (getAllComposedElementChildren) on every render of an element that provides something, and manual requestContext() callbacks still fire once only, which should be stated either way.

The docs currently say the injected value "will be just there at some point", which does not decide this. A maintainer decision, the showcase and the docs follow it.

主要语言
JavaScript
星标
30
派生
5
平均合并
1 小时 57 分钟
30 天内合并 PR
10

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

webtides/element-js 的其他 Issue

查看 webtides/element-js 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。