Attrs initialization without `@attr` decorator

Aberta
#207 4 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
35/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
typescript
Domínio
frontend

Direção de pesquisa

Comece lendo src/attr.ts em torno do guard inicializado e src/core.ts, onde controller envolve connectedCallback(). Reproduza o exemplo de InfoMessage com initializeAttrs(this, ['open']) e data-open="false". Está concluído quando a inicialização manual sem @attr aplica o valor do atributo em vez de deixar open como true.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

@attr

Hi there 😄

After upgrading from v1.1.4 to v1.3.2, I noticed that my attributes were no longer shadowed by initializeAttrs(). I started digging and stumbled upon this piece of logic introduced in #191:

https://github.com/github/catalyst/blob/a8fb3ba59a4ac258d0fe64a50ecd3b6997f5f016/src/attr.ts#L39

It prevents initializeAttrs() from doing anything the second time around, thus skipping the manual initialization of attributes. Also, it seems like this change was one of the main things addressed by the above-mentioned PR.

So, what would be the correct way now to initialize the attributes without the @attr decorator?

Thanks!


Example

<script>
  class InfoMessage extends HTMLElement {
    open = true

    connectedCallback() {
      initializeAttrs(this, ['open'])
    }
  }

  controller(InfoMessage)
</script>

<info-message data-open="false"></info-message>
  1. controller(InfoMessage) wraps original connectedCallback() and calls:

https://github.com/github/catalyst/blob/a8fb3ba59a4ac258d0fe64a50ecd3b6997f5f016/src/core.ts#L14

  1. InfoMessage is marked as initialized (attrs.ts):

https://github.com/github/catalyst/blob/a8fb3ba59a4ac258d0fe64a50ecd3b6997f5f016/src/attr.ts#L40

  1. The original connectedCallback() is executed, but initializeAttrs() would hit that early-return condition.
  2. this.open is stuck in its default state (true) 😔
Linguagem predominante
TypeScript
Estrelas
1.4k
Forks
61
Merge médio
1d 15h
PRs com merge (30d)
8

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de github/catalyst

Todas as issues de github/catalyst

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.