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 a "computed" observer #93

Open
ggael opened this issue Jul 1, 2024 · 0 comments
Open

Add a "computed" observer #93

ggael opened this issue Jul 1, 2024 · 0 comments

Comments

@ggael
Copy link

ggael commented Jul 1, 2024

I've started to write a computed decorator that behave like computed variables in vue, and I'm wondering whether this could be a welcome addition to vuejs?

It is based on traitlets.ObserveHandler. To make it work I've also borrowed the as_refs and create_ref_and_observe functions from VueTemplateWidget.py. Exposing those functions or integration this decorator in ipyvue would avoid code duplication.

Contrary to vuejs, dependencies must be explicitly listed.

Usage example:

from vue_computed import computed

class MyComponent(v.VuetifyTemplate):
    val1 = traitlets.Float(2.3).tag(sync=True)
    val2 = traitlets.Float(4.5).tag(sync=True)
    
    @computed('val1','val2')
    def vue_val3(self) -> traitlets.Float:
        return self.val1 + self.val2

    @traitlets.default('template')
    def _template(self):
        return '''
        <template>
            <div>{{val3}}</div>
        </template>
        '''

vue_computed.py.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant