Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

@onGet and @onSet custom hooks #16

Open
kaleidawave opened this issue Oct 17, 2020 · 0 comments
Open

@onGet and @onSet custom hooks #16

kaleidawave opened this issue Oct 17, 2020 · 0 comments
Labels
client-side-reactivity Reflection of updates to state on the view enhancement New feature or request server-hydration The backwards interpretation of server markup

Comments

@kaleidawave
Copy link
Owner

Currently there several types of bindings:

export enum ValueAspect {
Attribute, // Affects a specific attribute of a node
Data, // A components data
InnerText, // Affects the inner text value of a node
Iterator, // Affects the number of a children under a node / iterator
Conditional, // Affects if a node is rendered TODO not visible but exists
DocumentTitle, // Affects the document title
SetHook, // Hook to method on a class
Style // A css style
}

Currently set hook is not implemented. It would consist of adding a @onSet decorator to methods in the component class definition that would fire when the value parsed in as a argument is updated (the same way it works with updating the view via the DOM)

Example usage:

class SomeComponent extends Component<{title: string}> {
    @onSet(title)
    titleUpdate(value) {
        console.log("Title has updated to", value)
    }
}

Where value is the new updated value.

There could also be an opportunity for a @onGet decorator which would decorate a method that would return a value for manual server hydration. This could be used in places where Prism analysis for hydration fails. This would not be the same as a computed property. Once the hydration is needed and the @onGet method is fired and returns a value to the state then further gets to the property would return that in state rather than call the @onGet method again

@kaleidawave kaleidawave added enhancement New feature or request client-side-reactivity Reflection of updates to state on the view server-hydration The backwards interpretation of server markup labels Oct 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
client-side-reactivity Reflection of updates to state on the view enhancement New feature or request server-hydration The backwards interpretation of server markup
Projects
None yet
Development

No branches or pull requests

1 participant