Comments (13)
@dalanmiller correct me if I'm wrong, but it seems like this could be accomplished simply by merging the response from collection.store(...)
into the original object?
var todo = {
task: "babelify everything",
completed: false
};
todos.store(todo).then((result) => {
Object.assign(todo, result);
console.log(todo.id) // -> <uuid_from_server>
})
Given that this is so easy to implement in user-land, I kinda don't think we shouldn't do it by default. Especially since it relies on the assumption that people aren't reusing the object they originally passed in for other purposes.
That said, in framework-specific wrappers like for Angular or React, it probably does make sense. I just don't think we should in the core Fusion client.
from horizon.
I think the real problem with generating the ID on the server is that it makes optimistic updates really hard (though I'm not 100% sure if there might be an easy way around this).
from horizon.
Can you elucidate that @coffeemug ?
from horizon.
If the id is created on the server, you have to wait for the round trip in order to find out what the id was, or you have to be able to predict what the id will be (maybe a hash of some information the client has... some other hare-brained scheme)
from horizon.
Ahh sorry, I read @coffeemug's comment backwards before ingesting caffeine, I read creating id
s on the client.
But if we do have a means of creating an id
on the client with a wide enough key space that collisions aren't a realistic problem, this wouldn't be such an issue right? This is what I've been doing in the quick examples I created under the /examples dir using a javascript UUID generator snippet I found in the React docs.
from horizon.
I agree, client UUIDs shouldn't be a problem, and it is the easiest way to allow optimistic updates
from horizon.
We could codify this when we implement #52, we either use the id
that the user created or we generate a new one client-side when creating a new document. Something like:
var myDoc = {foo: bar, id: 123}
var myDoc2 = {foo: 'bar'}
fusion.createAndKeepUpdated(myDoc) // id: 123 inserted
fusion.createAndKeepUpdated(myDoc2) // client-side uuid generated
(totally bogus hypothetical api notwithstanding)
from horizon.
That's a good point @deontologician. What if I want to "insert and attach` versus just sync between db and view which is the functionality suggested in #52.
// Insert a document and keep it updated
d = {id: 1, text: "Hello"};
collection.insert(d).attach(); // Modifications on the server come back and update `d`
// versus
d = {id: 1, text: "Hello"};
collection.insert(d);
collection.find(d).subscribe().attach(d);
from horizon.
Originally posted by @danielcompton in issue #42
Firebase, Relay, and Meteor have built in latency compensation in their client side libraries. Updates are optimistically applied, and then 'committed' client-side once the confirmation comes back from the server.
As we discovered in our RethinkDB websockets project (pre-fusion), the richer your query model, the more difficult latency compensation is. We were running full REQL queries on the client, it is very difficult to simulate updates without something like Reqlite. Firebase has the easiest time of it because their query model is so impoverished.
Related links:
http://info.meteor.com/blog/optimistic-ui-with-meteor-latency-compensation
https://github.com/neumino/reqlite
https://facebook.github.io/relay/docs/guides-mutations.html#optimistic-updates
https://www.firebase.com/docs/web/guide/offline-capabilities.html
from horizon.
For email people: title changed from "Document state boomerang? (Optimistic updates)" to "Optimistic updates"
from horizon.
I built a simple example of an app with optimistic updates using Horizon and FreezerJS: https://github.com/segphault/rethinkdb-optimistic-demo/blob/horizon/client/tundra.js
I needed to set the id for new objects on the client side, as expected. I used a simple third-party uuid library from npm for that.
from horizon.
Are we still down for adding horizon.uuid()
to the client API?
from horizon.
I don't think this by itself solves optimistic updates quite yet, at least with the default .watch({ rawChanges: false })
setting. Once we have document versioning and timestamps in changefeeds, we should be able to cook something up.
I am ambivalent about putting .uuid()
in. Essentially we'll just be re-exporting a dependency, so I don't know if there's any good reason to put it into the Horizon object. Though I don't have a strong opinion
from horizon.
Related Issues (20)
- debug: Rejecting Client without 'rethinkdb-horizon-v0' protocol()
- Roadmap HOT 9
- Organizational Meeting (April 5th) HOT 8
- Disable websockets option HOT 4
- Typo in embedded server documentation
- Error: Operation not permitted. HOT 4
- Let's Encrypt untrusted cert HOT 1
- iOS Websocket fatally fails when sending a frame over ~40kb
- [bug] "find" is required HOT 1
- Support for programmatic search filters in findAll method
- Using "rethinkdb" as an alias for the hz serve CLI connect options would failed
- /usr/app doesn't contain an .hz directory HOT 2
- Project dead ? HOT 39
- Website id down from last few days
- What is the best solution to upload files to horizen ??
- Your website's certificate is fscked up
- Please server on for this site. HOT 4
- Github will soon not support the authentication method
- auth_redirect = "/?parameter=foe" in config.toml cause token to not be successfuly created HOT 1
- [website] horizon.io taken by blockchain gaming company HOT 5
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 horizon.