Can't succeed in subclassing RESTAdapter and RESTSerializer


#1

I can’t seem to understand how to implement an ember-data store. Here it says that I need to implement an adapter and a serializer. The problem is, I don’t know how to implement them. At first Ember would not load because it tried to call the extract method of my serializer, which didn’t have any. Implementing it solves the issue, but the data doesn’t arrive to the view.

I can’t find some documentation on how to implement that method and the others that are required. Also, can you please enlighten me about why using extend does not work in the majority of cases (Ember can’t find the methods), while if I use reopen or reopenClass it does?

OK I solved it like this. Any suggestions?

App = require './app'


RestSerializer = DS.RESTSerializer.reopenClass
  extract: (store, type, adapterPayload, records, method) ->
    typeKey = type.typeKey
    if method == 'findAll'
      adapterPayload
    else
      payload = {}
      payload[typeKey] = adapterPayload


RestAdapter = DS.RESTAdapter.reopen
  host: 'http://localhost:1337'
  serializer: RestSerializer
  ajax: (url, method, hash) ->
    hash.crossDomain = true
    hash.xhrFields = { withCredentials: true }
    @._super url, method, hash


Store = DS.Store.extend
  adapter: RestAdapter,

module.exports = Store

Thanks in advance.