Coder Social home page Coder Social logo

Comments (4)

adamlwgriffiths avatar adamlwgriffiths commented on August 29, 2024

I suspect this may be related to the details in Py/JS Bridge

The wrapper around lists and dictionaries provide the same interface than native python types but due to restrictions in Brython, they are no subclasses of list/dict. This can lead to problems when passing this methods to other native python methods. Therefore a helper is provided to convert a wrapped Javascript object into a native python type.

However, when calling Object.to_py I still end up with a javascript object

Making the following changes:

    @computed
    def ids(self):
        data = Object.to_py(self.store.data)
        print(f'Object.to_py(self.store.data) = {data}')
        return data.keys()

I still end up with the same error, the print function outputs:

Object.to_py(self.store.data) = <Javascript Object object: [object Object]>

There seems to also be some conversion tied to the @getter decorator.
If I add a @getter function to the Store that is just return {} it still comes back as a JSObj.

from vue.py.

adamlwgriffiths avatar adamlwgriffiths commented on August 29, 2024

Ok, so it looks like the way to "fix" this is to use the bridge.List and bridge.Dict.

class Store(VueStore):
    d = {
        'a': 123,
        'b': 456,
    };
    l = [1,2,3,4]

    @getter
    def ddict(self):
        return dict(Dict(self.d))

    @getter
    def llist(self):
        return list(List(self.l))

This is pretty cumbersome.

Doing something like slicing an array becomes

def slice(self, start, stop):
    self.store.l = list(List(self.store.l))[start:stop]

I tried using @property decorator to make this a bit more streamlined, but the components get messed up when using them for component values.

The best solution I've found so far is to make a proxy object that wraps the store and have a tonne of conversion functions.

from vue.py.

stefanhoelzl avatar stefanhoelzl commented on August 29, 2024

Thanks for reporting your Issue.

Unfortunately I cannot reproduce the issue.
Here is the app.py I am running

from vue import VueComponent, VueStore, computed

class Store(VueStore):
    data = {
        'a': 123,
        'b': 456,
    }

class DataComponent(VueComponent):
    id: str
    template = '''
        <div
            :id="id">
            {{ data }}
        </div>
    '''
    @computed
    def data(self):
        return self.store.data[self.id]

DataComponent.register()  # in your example the DataComponent was not registered

class App(VueComponent):
    template = '''
        <div>
            <data-component
                v-for="id in ids"
                :key="id"
                :id="id"  # in your example the id prop was not set
            />
        </div>
    '''

    @computed
    def ids(self):
        print(f'self.store.data = {self.store.data}')
        return self.store.data.keys()


App("#app", store=Store())

with the vuepy.yml to enable vuex

scripts:
  vuex: true

from vue.py.

adamlwgriffiths avatar adamlwgriffiths commented on August 29, 2024

I had moved onto other things for a while and have come back with a clean slate.
Got the latest vue 2.x, etc.
And now this issue isn't occuring. Most curious.

from vue.py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.