Live data from Hacker News

Angular-data: data store and caching for Angular.js

angular-data.pseudobry.com

21–30 of 49 posts

Re: Angular-data: data store and caching for Angular.js

#21
post #14

"Before writing angular-data I used to create fleets of services for my various resources, each performing data management and communicating with a persistence layer." Can someone give me an example of this? I just use $http and populte the $scope models in callbacks so I don't really recognize the problem.

For those writing largish non-trivial apps its essential to separate concerns for maintainability and testability. Controllers and UI logic get separated from domain logic and your Model layer. $scope is no Model layer.

I understand. It would be nice to see an example though.

Re: Angular-data: data store and caching for Angular.js

#22
post #20

Anyone know why these high point submissions aren't on the front page? Is Hacker News ghosting/flagging these posts for any specific reason? Sorry to ramble a bit off topic.

It's on the front page at third place for me. What interface are you using to browse Hacker News?

Re: Angular-data: data store and caching for Angular.js

#23
This looks great! I wrote something similar but Angular-data looks more polished. One of the problems I was trying to solve was synchronizing the same piece of data in multiple places in the client app after the server had validated the data. To do this, I broadcast an event on the rootscope in the http callback. https://github.com/robbyronk/angular-model-sync/blob/master/...

Re: Angular-data: data store and caching for Angular.js

#24
post #14

"Before writing angular-data I used to create fleets of services for my various resources, each performing data management and communicating with a persistence layer." Can someone give me an example of this? I just use $http and populte the $scope models in callbacks so I don't really recognize the problem.

For those writing largish non-trivial apps its essential to separate concerns for maintainability and testability. Controllers and UI logic get separated from domain logic and your Model layer. $scope is no Model layer.

Yet angular-data doesn't seem to deal with model layer per say, but rather synchronization issues between what's somehow in the scope and the web services. To me that seems to be handled quite well with services and maybe factories for wrapping json into custom model classes.

It seems more meant ot be used as a caching layer that would wrap you webservice access services.

Re: Angular-data: data store and caching for Angular.js

#25
post #14

"Before writing angular-data I used to create fleets of services for my various resources, each performing data management and communicating with a persistence layer." Can someone give me an example of this? I just use $http and populte the $scope models in callbacks so I don't really recognize the problem.

A simple example would be storing data on your 'logged in user' on a large application that has multiple controllers/services.

A scope only extends as far as a particular controller/service. If you wanted every controller/service to have access to that user's data (eg. that user's ID), you would create a service that would store that data, and then inject that service into each place you need to access the data.

Re: Angular-data: data store and caching for Angular.js

#29

ELI5 why I'd use this in a regular project using say Rails and angular?

Angular doesn't really provide a data model, you generally have to roll your own for an app.

Think of this as client side ActiveRecord. It handles queries, relations, and syncing with the back end.

Re: Angular-data: data store and caching for Angular.js

#30
"Angular-data is very optimistic when it comes to caching. If you do DS.find('user', 5) angular-data will first look for that user in the data store. If that user is already in the data store then the promise returned by DS.find('user', 5) will immediately resolve with the user. If no user exists then (if using the http adapter) a GET request will be made, and the user returned by the server will be injected into the data store."

I couldn't find anything in the docs about invalidation. Is anybody aware of how to force invalidation of an object/collection?

Post reply on HN