getoutreach / epf

A framework for keeping your Ember.js apps in sync.
http://epf.io
MIT License
369 stars 33 forks source link

change in custom transform registration #97

Closed heartsentwined closed 10 years ago

heartsentwined commented 10 years ago

Another "issue" as a reference for future googlers. If there's a docs site or something like that, I'd be glad to contribute over there :smile:

In 0.1.3:

Em.onLoad 'Ember.Application', (app) ->
  app.initializer
    name: 'registerRawTransform'
    initialize: (container, application) ->
      container.lookup('serializer:main').registerTransform 'raw',
        deserialize: (serialized) -> serialized
        serialize: (deserialized) -> deserialized

0.1.4:

class Ep.RawTransform extends Ep.Transform
  deserialize: (serialized) -> serialized
  serialize: (deserialized) -> deserialized

Em.onLoad 'Ember.Application', (app) ->
  app.initializer
    name: 'registerRawTransform'
    initialize: (container, application) ->
      application.register 'transform:raw', Ep.RawTransform
ghempton commented 10 years ago

Thanks for posting this! Definitely need more docs.

I think with 0.1.4 you should be able to get away with not having the initializer. Ember's default resolver will automatically check the namespace.

heartsentwined commented 10 years ago

I thought the implementation of transformFor means that I have to register the transform beforehand?

ghempton commented 10 years ago

You only have to register it if you break conventions. By default container.lookup('transform:raw') will resolve to Namespace.RawTransform.

Ah actually as I type this, I see that you added it to the Ep namespace rather than your app's namespace. In that case you would have to register it.

heartsentwined commented 10 years ago

Oh thanks for the clarification! I'm still wrapping my head over the DI stuff at ember

ghempton commented 10 years ago

As an fyi, I have refactored the serialization layer and there is no longer a difference between serializers and transforms. The only practical application here is that the transform should be renamed to RawSerializer. Moreover, since transforms and serializers are now one and the same, you can actually have attributes with model types (e.g. Ep.attr 'post') but I digres....