I have worked with Ember-Data for almost a year for now. I’m using some third party API that I can’t change, so I have written a big custom adapter and lot of workarounds. I wanted to discuss few improvement ideas, before putting them to gitHub. Ideas are little bit of related to each other.
-
Singleton model. Sometimes there is a model that always has exactly one instance (at least on client side). Most used example of this is user session login=getSession (usually you only have exactly one active session). There are other cases too like give me some daily sales total number, give me total number of signed up users etc. Simple workaround is always to assign id 1 to this model in adapter. It would be better if there would be an option to define singleton model without having ID at all.
-
Add query to findById I have cases where I need to get one object with additional parameters. One use case is singleton object described in point 1 (sending username and password for getSession), but sometimes also for other queries. For one example I have getReport commend to get HTML report by report_id and I can pass some params there. Current workaround is doing findQuery and getting first object from the array, but it creates some extra work. I think it’s common use case and should be in Ember-Data. So findById(type, id) should be findById(type, id, query) or separate function findByIdAndQuery(type, id, query).
-
Defining findQuery params in a model and serialization for findQuery parameters There should be a way to define findQuery parameters in a model. Lets say I want to find some objects in a date range, then I want to define startDate and endDate. Object attribute is „date“, but „startDate“ and „endDate“ should be query parameters. For primitive data types it’s not a big problem, but complex types like Date, BigNumber etc need to go through serialization and transform mechanism. Currently I’m putting query parameters to the model together with model attributes, and improved findQuery code so all query parameters go through serialization process (currently this is not a case).
Ember-Data is a great library and makes things so much easier, hopefully it gets even better:)