emberjs / data

A lightweight reactive data library for web applications. Designed over composable primitives.
https://api.emberjs.com/ember-data/release
Other
3.03k stars 1.33k forks source link

ember-data issues since 2012. Maybe is there a way today? Integrating Push to Keep Client Data in Sync, Local Storage Support, Handling Bad Connections and Crashes: Gateway to Offline Support #5181

Closed ghost closed 6 years ago

ghost commented 7 years ago

I found this post from 2012 http://hawkins.io/2012/07/ember_wish_list/.

Since then something is changed, but not these points:

Maybe I'm wrong, but is there a way today to handle these problems?

lolmaus commented 6 years ago

I believe ServiceWorker is the solution to at least first two points. And it doesn't even require Ember Data to be modified.

lolmaus commented 6 years ago

As for the third point, is a much bigger problem than it may seem, mostly due to the necessity to deal with conflicts from concurrent edits from multiple users and even from multiple devices of a single user. Academic papers are being written to explore the matter and suggest possible solutions. I know two solutions based on such research: Conflict-free Replicated Data Types and Operational Transformation, each having multiple implementations.

Check out this awesome demo of OT at work. It exposes the complexity behind seemingly transparent conflict resolution.

Unfortunately, both CRDT and OT are virtually impossible to integrate into exisiting webapps. A webapp must be initially written with CRDT/OT in mind, otherwise your infrastructure will feel like two separate backends. This is because the CRDT/OT data persistence layer essentially eliminates the business logic layer (a backend framework) from your app infrastructure: the frontend directly communicates with the data layer. If you need to add some checks, routines, etc to user-data interaction, you'll have to employ data layer API hooks provided by a CRDT/OT framework (if any) instead of your cozy Rails/Phoenix/Symphony/etc pipeline.

And then there's Hoodie. Because it's based on CouchDB, it is extremely simple to use, and I believe it can be easily integrated with Ember Data (ED would communicate with the Hoodie frontend instead of the server). But because it's based on CouchDB, it only works for users in isolation. Once you need more than one user to interact with a data resource, you're in trouble. Hoodie does provide a way to do that, but it's an advanced, poorly documented path for the courageous (according to my findings a year ago).

There's also Orbit.js with decent Ember support, but I'm not familiar with it and dunno whether it provides any conflict resolution strategy. The readme and website don't mention "conflict" at all, though Orbit does look like an academic-grade solution to the problem. It does mention "client-first / serverless development", which might imply the same problem as Hoodie.

TL/DR: you can't make a frontend data layer offline-capable without tightly coupling it with a particular backend implementation.

ghost commented 6 years ago

If you need to add some checks, routines, etc to user-data interaction, you'll have to employ data layer API hooks provided by a CRDT/OT framework (if any) instead of your cozy Rails/Phoenix/Symphony/etc pipeline.

This is the point. CouchDB/PouchDB solution and Hoodie both miss this point. I need server check on every interaction. And I can also decide to throw an error if I want and stop all the pipeline.

But until today nothing in ember world can handle this situation.

Eg:

Am I miss something?

lolmaus commented 6 years ago

Am I miss something?

The Ember Data team will never make it tightly coupled to a certain backend implementation.

But you can do your own implementation, have Ember Data talk to your IndexedDB layer. Ember Data doesn't need to be modified for that purpose, just customize your adapter & serializer.

ghost commented 6 years ago

Yes I know. I said Ember world. Not ember-data. I can talk with IndexedDB, what we today don't have is the synchronization mechanism for save in offline layer and replicate on the online layer.

This is what we really miss.

Something like redux-offline. But with Redux is a lot easier, I think, cause of reducer actions history.

rwjblue commented 6 years ago

We generally preserve this issue tracker for managing bugs in Ember Data. This doesn't really seem like a bug report to me, it seems instead like a feature request? I think that an issue in emberjs/rfcs would likely be a better place for this...