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

Multiple listener fields #5

Closed
blackfyre opened this issue Sep 24, 2021 · 9 comments
Closed

Multiple listener fields #5

blackfyre opened this issue Sep 24, 2021 · 9 comments

Comments

@blackfyre
Copy link

blackfyre commented Sep 24, 2021

Is there a way to add multiple listener fields?
Currently only 1 listener seems to be working on each channel...

update: having the broadcaster field broadcast to multiple channel doesn't seem to solve the problem

@gldrenthe89
Copy link
Owner

Sorry no time to look in to currently. Cant remember te exact mechanics.

@Saifallak
Copy link
Contributor

haveing the same issue, any ideas?

@blackfyre
Copy link
Author

I've forked the repo and started working on the fix...

@Saifallak
Copy link
Contributor

Looking forward for it, please notify me ASAP that fix is done, i would appreciate it

@gldrenthe89
Copy link
Owner

should be fixed by:Saifallak in: #8

@Saifallak
Copy link
Contributor

Nope, it doesn't,,..
This should be reopened..
I hope someone fixes this

@gldrenthe89 gldrenthe89 reopened this Oct 30, 2021
@gldrenthe89
Copy link
Owner

Reopend

@blackfyre
Copy link
Author

blackfyre commented Nov 3, 2021

Soo... After a little bit of investigation, it seems that the problem is with VueJS and how Nova handles it.
VueJS tends to re-use the same component, which is fine for conserving memory and so on, but in our case, if the listener fields are of the same type, the same debounced update gets called every time. If there are multiple listener field types, it'll work just fine.

It's easy to fix, once you know the problem...
In the created hook, I've added the content of the calculateValue dynamically to the data object with an unique key, and called that key dynamically when required.

Due to the extensive modifications on the code base, I cannot share my fork atm... it's still a work in progress, however, here's the mixin created to do this 😄

import _ from "lodash";

export default {
    data() {
        return {
            updater: {}
        }
    },
    created() {
        Nova.$on(this.field.listensTo, this.messageReceived)

        this.$set(this.updater, this.field.attribute, _.debounce((force = false) => {
            this.calculating = true;

            Nova.request().post(
                `/zenosyne/calculatron/calculatron/${this.resourceName}/${this.field.attribute}`,
                this.field_values
            ).then((response) => {
                if (
                    !(response.data.disabled && this.field.isUpdating)
                    ||
                    force
                ) {
                    this.value = response.data.value
                }
                this.calculating = false;
            }).catch(() => {
                this.calculating = false;
            });
        }, 300));
    },
    methods: {
        messageReceived(message) {
            this.field_values[message.field_name] = message.value;
            this.calculateValue()
        },
        calculateValue(force = false) {
            this.updater[this.field.attribute](force);
        }
    }
};

@Saifallak
Copy link
Contributor

looking forward for your fork/solution @blackfyre

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

3 participants