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

Increment operator (++) not reactive on auto-subscription variable #2625

Closed
abastardi opened this issue Apr 30, 2019 · 1 comment · Fixed by #2634
Closed

Increment operator (++) not reactive on auto-subscription variable #2625

abastardi opened this issue Apr 30, 2019 · 1 comment · Fixed by #2634
Assignees
Labels

Comments

@abastardi
Copy link

abastardi commented Apr 30, 2019

import { writable } from 'svelte/store';

let count1 = 0;
const count2 = writable(0);

function increment1() {
    count1++;
}

function increment2() {
    $count2++;
}

Above, count++ is reactive, but $count++ (a store auto-subscription variable) is not.

The generated code is:

function increment2() {
    $count2++;
}

but should be:

function increment2() {
    $count2++; count2.set($count2);
}

This was confirmed as a bug on Discord.

REPL reproduction

@Conduitry Conduitry added the bug label Apr 30, 2019
@Conduitry Conduitry self-assigned this Apr 30, 2019
@Conduitry
Copy link
Member

My current idea is to fold the UpdateExpression branch into the AssignmentExpression branch here except to use node.argument instead of node.left when it's an update expression. This appears to fix this issue, but it causing one other test failure I haven't investigated yet.

Rich-Harris added a commit that referenced this issue May 4, 2019
fix invalidating stores with UpdateExpression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants