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

(@)computed not updated #1546

Closed
misantronic opened this issue May 16, 2018 · 2 comments
Closed

(@)computed not updated #1546

misantronic opened this issue May 16, 2018 · 2 comments

Comments

@misantronic
Copy link

misantronic commented May 16, 2018

[email protected]

I've had really good experiences with computed-values. Now, I've come to a case where the computed-value is simply not updated. Here the example:

@computed
public get assignedGroups(): Option[] {
    const { $: userJSON } = this.user;
    const { $: allRoles } = this.roles;

    if (userJSON && allRoles.length) {
        const userRoles = allRoles.filter(r => {
            for (const u of r.users || []) {
                if (u.id === userJSON.id) {
                    return true;
                }
            }
            return false;
        });

        return userRoles.map(role => ({
            label: role.name,
            value: role.id
        }));
    }

    return [];
}

@computed
public get hasAssignedGroups(): boolean {
    console.log('hasAssignedGroups', this.assignedGroups);
    return (
        this.assignedGroups.some(group =>
            this.companyRoles.$.some(cRole => cRole.id === group.value)
        ) === false
    );
}

what's fine and updating is assignedGroups. Whenever the observables referenced inside change, this value is re-calculated and all is good.
now, hasAssignedGroups has a dependency on assignedGroups, so hasAssignedGroups should recalculate when assignedGroups changes. But it does not. It just consoles out the first time and then nothing ever changes.

@misantronic misantronic changed the title computed not updated (@)computed not updated May 16, 2018
@mweststrate
Copy link
Member

mweststrate commented May 16, 2018 via email

@misantronic
Copy link
Author

I went on creating an example on jsfiddle, there it all worked fine. That got me thinking and the problem was that r.users is a Set which cannot be observable. So I converted it to an observable array and that solved it.

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

2 participants