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

Add watch decorator that will invalidate when the property is set #74

Closed
agubler opened this issue Aug 21, 2018 · 0 comments
Closed

Add watch decorator that will invalidate when the property is set #74

agubler opened this issue Aug 21, 2018 · 0 comments
Labels
enhancement New feature or request next Issue/Pull Request for the next major version

Comments

@agubler
Copy link
Member

agubler commented Aug 21, 2018

Enhancement

Often widgets contain internal state that, when set, require the user to call this.invalidate() to ensure the widget is re-rendered.

Add a decorator for watching internal properties so that when they are set it will automatically call invalidate

class MyWidget extends WidgetBase {

    @watch()
    private _myState = 0;

    private _increment() {
         this._myState = this._myState + 1; // this automatically calls invalidate
    }

    protected render() {
        return v('div', [ 
            v('button', { onclick: this._increment }, [ 'Increment' ]),
            `${this._myState}`)
        ]);
    }
}
@agubler agubler added enhancement New feature or request next Issue/Pull Request for the next major version labels Aug 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request next Issue/Pull Request for the next major version
Projects
None yet
Development

No branches or pull requests

1 participant