Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gem] CSS state and js state #179

Closed
mantou132 opened this issue Jul 11, 2024 · 3 comments
Closed

[gem] CSS state and js state #179

mantou132 opened this issue Jul 11, 2024 · 3 comments
Labels

Comments

@mantou132
Copy link
Owner

mantou132 commented Jul 11, 2024

  1. 其他装饰字段不要直接赋值,但是 @state 确是要赋值的
  2. 容易和 js state 混淆

下面这个方案和 state 一样怎么保证类型:

class MyElement extends HTMLElement {
  cssState = {}
  state = {}

  updated = () => {
    this.setState({ });
    this.setCSSState({ });
  }
}
@mantou132 mantou132 changed the title CSS state and js state [gem] CSS state and js state Jul 11, 2024
@mantou132
Copy link
Owner Author

mantou132 commented Jul 18, 2024

like emitter:

  • 继承
  • 同时具备访问和设置功能
  • 只需要一个类型标记
class MyElement extends HTMLElement {
  @state state: StateFn<{a: number}> = { a: 1 }
}

@mantou132
Copy link
Owner Author

mantou132 commented Jul 18, 2024

取消 @state 。自动在初始化时将 state 中的 Boolean 值转换为 css 状态

这个方案不能继承,只有装饰器才能继承字段值 // 目前状态也不能继承

class My {
  state = {  }

  mounted () {
    this.setState()
  }
}

@mantou132 mantou132 pinned this issue Jul 19, 2024
@mantou132 mantou132 unpinned this issue Jul 29, 2024
@mantou132 mantou132 pinned this issue Jul 29, 2024
@mantou132
Copy link
Owner Author

mantou132 commented Jul 31, 2024

修改 js state:

class My {
  #state = createState<State>({ a: 2 })

  render() {
    this.#state.a;
    this.#state({ a: 1 })
  }
}

怎么让 devtools 读取?// 使用 internals

css state 只适合用 @state:

  • 文档生成
  • devtools 读取
  • 外部元素读取和修改 // 例如 duoyun-ui

@mantou132 mantou132 reopened this Jul 31, 2024
mantou132 added a commit that referenced this issue Aug 5, 2024
移除 @Style #183
添加 @willMount @mounted @render 装饰器 #159
内部元素生命周期使用装饰器
添加 createState #179
mantou132 added a commit that referenced this issue Aug 5, 2024
移除 @Style #183
添加 @willMount @mounted @render 装饰器 #159
内部元素生命周期使用装饰器
添加 createState #179
mantou132 added a commit that referenced this issue Aug 5, 2024
移除 @Style #183
添加 @willMount @mounted @renderTemplate 装饰器 #159
内部元素生命周期使用装饰器
添加 createState #179
mantou132 added a commit that referenced this issue Aug 5, 2024
移除 @Style #183
添加 @willMount @mounted @renderTemplate 装饰器 #159
内部元素生命周期使用装饰器
添加 createState #179
@mantou132 mantou132 unpinned this issue Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant