These are chat archives for js-data/js-data

2nd
Aug 2015
degamer106
@degamer106
Aug 02 2015 01:50
Is it OK to attach static methods to a resource?
Lets say my JSON data is an array of Holiday objects and I want to find when the next upcoming holiday is
Jason Dobry
@jmdobry
Aug 02 2015 02:07
put static methods on resources to your heart's content
var Foo = store.defineResource({
  name: 'foo',
  /** Static Methods **/
  beep: function () { ... }
});

/** More static methods **/
Foo.boop = function () { ... };
degamer106
@degamer106
Aug 02 2015 02:08
:)
Jason Dobry
@jmdobry
Aug 02 2015 02:08
There's always the chance I'll add a method that conflicts with something you've added
small chance
degamer106
@degamer106
Aug 02 2015 02:09
ah ok
Jason Dobry
@jmdobry
Aug 02 2015 02:10
You can avoid that through clever naming (a prefix or something), or nest static methods under the meta property, which I have vowed never to use:
var Foo = store.defineResource({
  name: 'foo',
  /** Static Methods **/
  meta: {
    beep: function () { ... }
  }
});
degamer106
@degamer106
Aug 02 2015 03:51
how do i add url parameters when i do an HTTP GET?
Jason Dobry
@jmdobry
Aug 02 2015 03:52
how are you doing the GET? your code?
degamer106
@degamer106
Aug 02 2015 03:53
/holidays?endDate=2015-12-31&limit=25&page=1&start=0&startDate=2015-01-01
Jason Dobry
@jmdobry
Aug 02 2015 03:53
what's the code?
degamer106
@degamer106
Aug 02 2015 03:54
did u want the Resource definition?
CompanyHolidays.findAll().then(function(response) {
$scope.upcomingHoliday = CompanyHolidays.first().upcoming();
})
Jason Dobry
@jmdobry
Aug 02 2015 03:55
CompanyHolidays.findAll(null, { params: { foo: 'bar' } })
degamer106
@degamer106
Aug 02 2015 03:55
ok
Jason Dobry
@jmdobry
Aug 02 2015 03:55
You might as well just do CompanyHolidays.findAll({ foo: 'bar' })
degamer106
@degamer106
Aug 02 2015 03:56
k got it
david yang
@davidyang
Aug 02 2015 04:25
@jmdobry if you want to access custom endpoints, is the idea to create statics that would use the DSHttpAdapter's underlying GET methods and then handle inject
I see you can override an endpoint but nothing else obvious in DSHttpAdapter.getEndpoint that would let you customize the url
Jason Dobry
@jmdobry
Aug 02 2015 04:26
Yep, you can definitely do that. I do it all the time. I build the urls myself.
The other option is to define "actions"
trades flexibility for convenience
degamer106
@degamer106
Aug 02 2015 14:17
how do u decide if something should go under "computed" or "methods"?
Jason Dobry
@jmdobry
Aug 02 2015 14:29
computed should probably be for things that require only light computation, and for which you want the convenience of simple accessing a property on the entity
Roland Quast
@rquast
Aug 02 2015 23:43
I've wondered about computed properties a bit too.. the biggest benefit (apart from formatting/easy access) I can see is binding to a computed property. Can anyone recommend an article on the topic?