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

[inline-mod]: Mutable root state #18

Closed
Fryuni opened this issue Jan 27, 2024 · 0 comments
Closed

[inline-mod]: Mutable root state #18

Fryuni opened this issue Jan 27, 2024 · 0 comments
Labels
enhancement New feature or request pkg/inline-mod

Comments

@Fryuni
Copy link
Owner

Fryuni commented Jan 27, 2024

Currently all root entries in the serialized virtual module are immutable, even if they were mutable on the original code.

Example:

let count = 0;

inlineMod({
  constExport: {
    increment() { count++; },
    decrement() { count++; },
  },
});

In this case the count won't change across invocations because it is included immutably into the virtual module.

The workaround for this is to have the mutable property inside of an object. This works:

const state = { count: 0 };

inlineMod({
  constExport: {
    increment() { state.count++; },
    decrement() { state.count++; },
  },
});

Maybe the first case could work out-of-the-box.

@Fryuni Fryuni added enhancement New feature or request pkg/inline-mod labels Jan 27, 2024
@Fryuni Fryuni closed this as completed Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pkg/inline-mod
Projects
None yet
Development

No branches or pull requests

1 participant