Skip to content
This repository was archived by the owner on Jul 28, 2023. It is now read-only.

Make wp-context inheritable and extensible#139

Merged
DAreRodz merged 10 commits intomain-wp-directives-pluginfrom
make-context-extensible
Jan 26, 2023
Merged

Make wp-context inheritable and extensible#139
DAreRodz merged 10 commits intomain-wp-directives-pluginfrom
make-context-extensible

Conversation

@DAreRodz
Copy link
Copy Markdown
Collaborator

@DAreRodz DAreRodz commented Jan 26, 2023

What

(Re) implement the wp-context directive so nested contexts can inherit properties from the parent context. Inherited properties can also be shadowed if redeclared in the child context.

Why

At this moment, a child context replaces the parent context entirely, but contexts should be inheritable and extensible to cover most use cases.

How

Implementing a mergeDeepSignals function that copies signals from the parent context only if they're not already defined in the child context. That would allow, for example, changes in inherited properties from the child context to be reflected in the parent one, except in the case those properties are shadowed.

@DAreRodz DAreRodz linked an issue Jan 26, 2023 that may be closed by this pull request
@DAreRodz DAreRodz marked this pull request as ready for review January 26, 2023 13:52
@DAreRodz DAreRodz requested a review from luisherranz January 26, 2023 13:52
Copy link
Copy Markdown
Member

@luisherranz luisherranz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful. I think it's ready to merge 🙂

Oh, and thanks for starting to use TypeScript, by the way.

Comment on lines +18 to +23
<button
data-testid="parent prop1"
name="prop1"
value="modifiedFromParent"
wp-on:click="actions.updateContext"
>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using attributes as function arguments is smart. You are always coming up with interesting patterns, David 😄

@DAreRodz DAreRodz merged commit 0a1de28 into main-wp-directives-plugin Jan 26, 2023
@DAreRodz DAreRodz deleted the make-context-extensible branch January 26, 2023 15:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Merge inherited wp-context properties from a parent instance

2 participants