-
Notifications
You must be signed in to change notification settings - Fork 421
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
can.connect for advanced persistent data behavior #1213
Comments
Related: #1126 |
Maybe separate services might provide a better decoupling than mixins. It can potentially be hard to figure out what has been mixed in and effectively the Person model is still coupled to how it connects. I don't think it would make too much of a difference except for that you have a separate service object: var Person = can.Map.extend({ ... });
// Hook up custom connector
var userService = can.connect({
findAll: function(params) {
return new Promise(); // ...
},
findOne: function(id) {
return new Promise(); // ...
}
}, Person);
// Hook up via REST API
var userService = can.connect(can.connect.rest('/users'), Person);
// Hook up via Feathers
var userService = can.connect(can.connect.feathers('/users'), Person);
userService.findOne(10).then(function(person) {
console.log(person instanceof Person);
});
userService.findAll().then(function(people) {
console.log('Found ' + people.length + ' users');
});
userService.on('created', function(person) {
console.log('Someone created a new user', person);
}); |
The goal of this is to maintain can.Model's API. @daffl I'm not sure what you are showing or what you mean by "services". There's unlikely anything better than a "mixin" for decoupling the mixin's themselves. In your example, userService would still be coupled to "Person". |
What is the API that a connector is implementing here? I want to write a custom connector that connects to indexeddb or some other storage backend that probably won't be in core. How would I do that here? Also, you can connect multiple backends it seems, so how does it determine which gets called? |
I've not started showing how these would be implemented. The first step is to identify common use cases and then see what implementing them might be like. Sent from my iPhone
|
@daffl The idea with "services" is really cool. Actually it can be an implementation of Repository Pattern. Which allows to hide storage and transport level details from the model itself. Quite usefull for advanced scenarios like unit-testing or switching between online and offline application mode. |
The service would be coupled to Even with services introduced as a new concept this can still be API backwards compatible because the service basically is the same thing as the mixin object. Simplified something like:
Would then provide the same API as can.Model. |
Is there any progress for this issue? BTW wy can.Model doesn't have default method like |
findOne can do this Sent from my iPhone
|
I use this method, but I'm not sure that it will work correctly if model instance is not in store.
|
This is available in https://github.com/canjs/can-connect |
VOTE HERE
Goal
Create a plugin that allows mixin behavior for CRUD lifecycle events. For example, creating a
Person
can.Map and adding RESTful behavior might look like:Proposed mixins
Model instance store
Provides the same behavior as the current model-store
Use
Implementation
Hooks into:
Realtime connection
Use
Use localStorage as a fall-through cache
Use
Live lists
Live lists would automatically put created items in the list when the realtime connection pushed a new item.
Use
Queue Plugin
Allows immediate saving and queuing of requests.
Use
Implementation
Hooks into:
The text was updated successfully, but these errors were encountered: