prism icon indicating copy to clipboard operation
prism copied to clipboard

@onGet and @onSet custom hooks

Open kaleidawave opened this issue 3 years ago • 0 comments

Currently there several types of bindings:

https://github.com/kaleidawave/prism/blob/9f76e8b7c3ebeaa811144cc5b587136d28d3bd1f/src/templating/template.ts#L50-L59

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 avatar Oct 17 '20 20:10 kaleidawave