Comments (3)
Hi @Toubat,
The reason this is not supported, is that "assigning elements in an array" is most of the time not multi-user proof.
Assume we have an array ["green", "red", "blue"]
;
Let's say Alice and Bob both change array[1]
at the same time, while being "offline":
- Alice does
array[1] = "purple"
- Bob does
array[1] = "orange"
When these changes sync, would you expect ["green", "purple", "blue"]
, ["green", "orange", "blue"]
or ["green", "purple", "orange", "blue"]
?
When dealing with lists / arrays, I think often you'd want the latter ["green", "purple", "orange", "blue"]
. An assignment doesn't seem "idiomatic" for this, as it's better represented by a delete and insert operation.
I think adding support for assignment in arrays will lead to a lot of confusion in multi-user scenarios, I think it's cleaner to recommend users to use alternative operations (inserting and removing elements separately)
from syncedstore.
Change your array of numbers to an array of objects with one single attribute. Then modify that attribute.
export const store = syncedStore({
todos: [] as Todo[],
myText: {} as { text?: any },
arr: [] as { value: number }[],
fragment: "xml"
});
store.arr.push({value:1});
store.arr[0].value = 42;
from syncedstore.
That's really helpful! Thank you for the detailed explanation!
from syncedstore.
Related Issues (20)
- Feature Request: Immer HOT 1
- Assign boxed objects
- `useMemo` not running when dependency array changes HOT 3
- errors nextjs
- [Bug] Typing issues with bun.sh
- Cannot store undefined in array
- More concise Vue integration
- History and really large updates
- Supporting array assignment HOT 2
- How to handle relations HOT 1
- Reactivity broken since updated @reactivedata/reactivity package released HOT 6
- Warning: `property not found on root doc $$typeof` HOT 1
- Move `@types/eslint` to `devDependencies`?
- Question: Why syncedStore wrap values from YDoc automatically? HOT 3
- Question: How many stores should you create? HOT 1
- Pushing or removing from array causes mobx computed to fire changes = number of array elements + 1
- Making a nested property collaborative rich text editor
- Moving an item between arrays gives error about content already being a part of the tree
- Not sure how to add a new XML fragment HOT 3
- How can I use Y.Map when I init the store? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from syncedstore.