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

Have option to use either: ngResource or js-data model layer #19

Closed
Toub opened this issue Apr 15, 2015 · 6 comments
Closed

Have option to use either: ngResource or js-data model layer #19

Toub opened this issue Apr 15, 2015 · 6 comments
Labels

Comments

@Toub
Copy link

Toub commented Apr 15, 2015

As mentioned in #16 "Bower dependencies", we should introduce an abstraction layer such as js-data.

The basic:

  • add bower dependency: js-data-angular

  • load the module 'js-data' in client app.js

  • configure the default behavior (by default use http://www.js-data.io/docs/dshttpadapter):

    DSProvider.defaults.basePath = '/api';
    DSProvider.defaults.idAttribute = '_id'; // for mongo-db

  • define resources and relations-ships:

    DS.defineResource{
    name: 'users'
    });

  • use it anywhere:

    DS.findAll('users').then(function (users) {
    $scope.users = users;
    });

The entities are cached by default so I love to use it in combination with web sockets to synchronize the cached collection with the server.

It could be a good idea to write a custom adapter to cover this case.

@ericmdantas
Copy link
Owner

Just as a reference for others, here's a good video about it.

@ericmdantas
Copy link
Owner

Just a question:

By using js-data, we'd still have the model for forms, right? Like the todo.model.js.

@jgodi
Copy link

jgodi commented Apr 16, 2015

Yes, you can see it here. http://www.js-data.io/v1.8.0/docs/js-data-angular

For me I can live without this js-data. I use Ember Data in a project and it over complicates things more so then some applications need. Would be nice for this to be an opt-in feature rather in a core feature.

@Toub
Copy link
Author

Toub commented Apr 16, 2015

You don't have to define all properties of your model, but you can: http://www.js-data.io/v1.8.0/docs/dsdefineresource

Here is how you can validate the model: http://www.js-data.io/v1.8.0/docs/schemata--validation

Maybe that jgodi is right, and that the user should be able to choose if using js-data, ngresource, restangular...

But the good of js-data is the abstraction layer so you can do powerfull things or change the way you store your data without impact on your services and controllers.

@ericmdantas
Copy link
Owner

For some reason the links are broken to me, I'll take a look when I get home.

But I agree with the opt thing.

For now, we could leave it between ngResource and js-data.

@ericmdantas ericmdantas changed the title Replace ngResource by js-data model layer Have option to use either: ngResource or js-data model layer Apr 16, 2015
@ericmdantas
Copy link
Owner

Droping from core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants