Skip to content

Add a "computed" observer #93

@ggael

Description

@ggael

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions