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

store.commit causes errors #24

Closed
adamlwgriffiths opened this issue Sep 19, 2021 · 2 comments
Closed

store.commit causes errors #24

adamlwgriffiths opened this issue Sep 19, 2021 · 2 comments
Labels
feedback required More information about the issue are required

Comments

@adamlwgriffiths
Copy link

adamlwgriffiths commented Sep 19, 2021

When using the "store.commit" method, I get an error before the getter function is called.
This is preventing me from having complex setters in the store.

Example app to demonstrate

from vue import VueComponent, VueStore, mutation

class Store(VueStore):
    test_value = 1

    @mutation
    def increment_test_value(self, value):
        print('increment')
        self.test_value += value


class App(VueComponent):
    template = '''
        <div>
            <button @click="set_value">{{ value }}</button>
        </div>
    '''
    def set_value(self, event):
        self.store.commit('increment_test_value', 1)

    @computed
    def value(self):
        return self.store.test_value

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

html

<body>
    <div id="app"></div>
</body>

Output:

Error
    at Object._b_.AttributeError.$factory (eval at $make_exc (brython.min.js:7), <anonymous>:1:2566)
    at $B.JSObj.__getattribute__ (brython.min.js:7)
    at Object.$B.$getattr (brython.min.js:7)
    at wrapper275 (eval at run_py (brython.min.js:7), <anonymous>:165:296)
    at s.wrapper63 (eval at run_py (brython.min.js:7), <anonymous>:308:185)
    at s.<anonymous> (brython.min.js:7)
    at vuex.min.js:6
    at vuex.min.js:6
    at Array.forEach (<anonymous>)
    at vuex.min.js:6
brython.min.js:7 Traceback (most recent call last):
  File /static/vue/decorators/base.py line 32, in set_value
    return Object.to_js(fn(*args, **kwargs))
  File /static/test/app.py line 21, in set_value
    self.store.commit('increment_test_value', 1)
  File /static/vue/bridge/vuex_instance.py line 42, in commit
    self.__commit__(mutation_name, {"args": args, "kwargs": kwargs})
  File /static/vue/decorators/base.py line 32, in wrapper
    return Object.to_js(fn(*args, **kwargs))
  File /static/vue/decorators/mutation.py line 19, in wrapper
    )
brython.min.js:7 AttributeError: get
brython.min.js:7 error Error
    at Object._b_.AttributeError.$factory (eval at $make_exc (brython.min.js:7), <anonymous>:1:2566)
    at $B.JSObj.__getattribute__ (brython.min.js:7)
    at Object.$B.$getattr (brython.min.js:7)
    at wrapper275 (eval at run_py (brython.min.js:7), <anonymous>:165:296)
    at s.wrapper63 (eval at run_py (brython.min.js:7), <anonymous>:308:185)
    at s.<anonymous> (brython.min.js:7)
    at vuex.min.js:6
    at vuex.min.js:6
    at Array.forEach (<anonymous>)
    at vuex.min.js:6
brython.min.js:7 attribute commit of self s {_committing: true, _actions: {…}, _actionSubscribers: Array(0), _mutations: {…}, _wrappedGetters: {…}, …} ƒ (t,e,n){return u.call(i,t,e,n)} (2) ['increment_test_value', {…}] Arguments(2) ['increment_test_value', {…}, callee: ƒ, Symbol(Symbol.iterator): ƒ]
brython.min.js:7 Error
    at Object._b_.AttributeError.$factory (eval at $make_exc (brython.min.js:7), <anonymous>:1:2566)
    at $B.JSObj.__getattribute__ (brython.min.js:7)
    at Object.$B.$getattr (brython.min.js:7)
    at wrapper275 (eval at run_py (brython.min.js:7), <anonymous>:165:296)
    at s.wrapper63 (eval at run_py (brython.min.js:7), <anonymous>:308:185)
    at s.<anonymous> (brython.min.js:7)
    at vuex.min.js:6
    at vuex.min.js:6
    at Array.forEach (<anonymous>)
    at vuex.min.js:6
brython.min.js:7 Traceback (most recent call last):
  File /static/vue/decorators/base.py line 32, in set_value
    return Object.to_js(fn(*args, **kwargs))
  File /static/test/app.py line 21, in set_value
    self.store.commit('increment_test_value', 1)
  File /static/vue/bridge/vuex_instance.py line 42, in commit
    self.__commit__(mutation_name, {"args": args, "kwargs": kwargs})
  File /static/vue/decorators/base.py line 32, in wrapper
    return Object.to_js(fn(*args, **kwargs))
  File /static/vue/decorators/mutation.py line 19, in wrapper
    )
brython.min.js:7 AttributeError: get
vue.min.js:6 Error
    at Object._b_.AttributeError.$factory (eval at $make_exc (brython.min.js:7), <anonymous>:1:2566)
    at $B.JSObj.__getattribute__ (brython.min.js:7)
    at Object.$B.$getattr (brython.min.js:7)
    at wrapper275 (eval at run_py (brython.min.js:7), <anonymous>:165:296)
    at s.wrapper63 (eval at run_py (brython.min.js:7), <anonymous>:308:185)
    at s.<anonymous> (brython.min.js:7)
    at vuex.min.js:6
    at vuex.min.js:6
    at Array.forEach (<anonymous>)
    at vuex.min.js:6
@stefanhoelzl
Copy link
Owner

for me your example app run without an issue (computed needs to be imported tough).

What is our vuepy version, browser and operation system?
How do you deploy your vuepy app?

@stefanhoelzl stefanhoelzl added the feedback required More information about the issue are required label Mar 22, 2022
@adamlwgriffiths
Copy link
Author

Again, I tried to cut down a minimal example and did it wrong =P.
You're correct in that the code works with computed imported.

I do however see (with bython 3.10.6):

empty stack
increment
empty stack

This "empty stack" I'm seeing in other callbacks in Vue.js libraries.
I'll close this and open another issue as this seems to be the cause of an issue when using vue-socketio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback required More information about the issue are required
Projects
None yet
Development

No branches or pull requests

2 participants