Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE ds-transform-pass-options] pass options to DS.Transform #4086

Merged
merged 1 commit into from
Jan 27, 2016
Merged

[FEATURE ds-transform-pass-options] pass options to DS.Transform #4086

merged 1 commit into from
Jan 27, 2016

Conversation

pangratz
Copy link
Member

This feature passes the options hash defined for an attribute to the
serialize and deserialize methods of DS.Transform:

// app/models/post.js
export default Model.extend({
  text: DS.attr('text'),

  otherText: DS.attr('text', {
    lowercaseInput: true,
    uppercaseOutput: true
  })
});

// app/transforms/text.js
export default DS.Tranform.extend({
  serialize(value, options) {
    if (options.uppercaseOutput) {
      return value.toUpperCase();
    }

    return value;
  },

  deserialize(value, options) {
    if (options.lowercaseInput) {
      return value.toLowerCase();
    }

    return value;
  }
});

This implements emberjs/rfcs#1.

This feature passes the options hash defined for an attribute to the
`serialize` and `deserialize` methods of `DS.Transform`:

```js
// app/models/post.js
export default Model.extend({
  text: DS.attr('text'),

  otherText: DS.attr('text', {
    lowercaseInput: true,
    uppercaseOutput: true
  })
});

// app/transforms/text.js
export default DS.Tranform.extend({
  serialize(value, options) {
    if (options.uppercaseOutput) {
      return value.toUpperCase();
    }

    return value;
  },

  deserialize(value, options) {
    if (options.lowercaseInput) {
      return value.toLowerCase();
    }

    return value;
  }
});
```
@knownasilya
Copy link
Contributor

@pangratz you beat me to it 👍

igorT added a commit that referenced this pull request Jan 27, 2016
[FEATURE ds-transform-pass-options] pass options to DS.Transform
@igorT igorT merged commit 8b0e53c into emberjs:master Jan 27, 2016
@pangratz pangratz deleted the ds-transform-pass-options branch January 27, 2016 17:55
@josemarluedke
Copy link
Contributor

Hey @pangratz! I need to use this feature with json api instead of just the json adapter. Does this feature was supposed to be in json api as well? Or it was specifically done just for json?

@knownasilya
Copy link
Contributor

This feature should be adapter agnostic.

@pangratz
Copy link
Member Author

@josemarluedke this basically should be an adapter agnostic change, but it looks like you found a bug. Thanks for fixing in #4425 🚀 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants