emka26
emka26

Reputation: 443

Override file in ember addon

I need to override this method: normalize(payload, modelName)

in ember-cli-mirage addon and serializer-registry file

https://github.com/samselikoff/ember-cli-mirage/blob/master/addon/serializer-registry.js#L21

I have no idea where to put file to override it in my ember project.

Upvotes: 1

Views: 104

Answers (1)

Sam Selikoff
Sam Selikoff

Reputation: 12694

Do you need to override it for all serializers or just one?

If all, you could so something like this on the application serializer:

// mirage/serializers/application.js
import { JSONAPISerializer } from 'ember-cli-mirage';

export default JSONAPISerializer.extend({

  normalize(payload, modelName) {
    // This is how to call "super"
    let jsonApiDocument = JSONAPISerializer.prototype.serialize.apply(this, arguments);

    // Tweak the document

    return jsonApiDocument;
  }

});

Note that normalize() is only used by POST and PUT shorthands.

Upvotes: 2

Related Questions