How to use the ember-data.Transform function in ember-data

To help you get started, we’ve selected a few ember-data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github danielspaniel / ember-data-factory-guy / tests / dummy / app / transforms / object.js View on Github external
import { isEmpty, typeOf } from '@ember/utils';
import DS from 'ember-data';

export default DS.Transform.extend({
  serialize: function(value) {
    return value ? JSON.stringify(value) : '{}';
  },
  deserialize: function(value) {
    if (isEmpty(value)) {
      return {};
    }
    if (typeOf(value) === "object") {
      return value;
    }
    if (typeOf(value) === 'string') {
      return JSON.parse(value);
    }
  }
});
github pouchdb-community / ember-pouch / addon / transforms / attachments.js View on Github external
import Ember from 'ember';
import DS from 'ember-data';

const {
  get,
  isNone
} = Ember;
const keys = Object.keys || Ember.keys;

export default DS.Transform.extend({
  deserialize: function(serialized) {
    if (isNone(serialized)) { return []; }

    return keys(serialized).map(function (attachmentName) {
      let attachment = serialized[attachmentName];
      return Ember.Object.create({
        name: attachmentName,
        content_type: attachment.content_type,
        data: attachment.data,
        stub: attachment.stub,
        length: attachment.length,
        digest: attachment.digest,
      });
    });
  },
github Flexberry / ember-flexberry-designer / addon / transforms / typemap.js View on Github external
import Ember from 'ember';
import DS from 'ember-data';

export default DS.Transform.extend({
  deserialize(serialized) {
    if (!serialized) {
      return serialized;
    }

    let ret = Ember.A();
    let parser = new DOMParser();
    let xmlDoc = parser.parseFromString(serialized, 'text/xml');

    if (xmlDoc) {
      let items = xmlDoc.getElementsByTagName('TypeMap');
      if (items.length > 0) {
        let arr = items[0].getElementsByTagName('*');
        for (let item of arr) {
          let obj = {
            name: item.tagName
github HospitalRun / hospitalrun-frontend / app / transforms / custom-fields.js View on Github external
import { inject as service } from '@ember/service';
import { get } from '@ember/object';
import { isEmpty } from '@ember/utils';
import DS from 'ember-data';
import uuid from 'uuid';

export default DS.Transform.extend({
  store: service(),

  deserialize(serialized) {
    if (isEmpty(serialized)) {
      return serialized;
    }
    return serialized.map((customField) => {
      let store = this.get('store');
      let record = store.push({
        data: {
          id: uuid.v4(),
          type: 'custom-field',
          attributes: customField
        }
      });
      return record;
github danielspaniel / ember-data-change-tracker / addon / transforms / object.js View on Github external
import DS from 'ember-data';
import Ember from 'ember';

export default DS.Transform.extend({
  serialize: function(value) {
    return value && JSON.stringify(value);
  },
  
  deserialize: function(value) {
    if (Ember.isEmpty(value)) {
      return {};
    }
    if (Ember.typeOf(value) === "object") {
      return value;
    }
    if (Ember.typeOf(value) === 'string') {
      return JSON.parse(value);
    }
  }
});
github HospitalRun / hospitalrun-frontend / app / transforms / custom-forms.js View on Github external
import EmberObject from '@ember/object';
import { inject as service } from '@ember/service';
import { isEmpty } from '@ember/utils';
import DS from 'ember-data';

export default DS.Transform.extend({
  store: service(),

  deserialize(serialized) {
    if (isEmpty(serialized)) {
      return serialized;
    }
    let customFormKeys = Object.keys(serialized);
    let deserialized = EmberObject.create();
    customFormKeys.forEach((customFormId) => {
      deserialized.set(customFormId, EmberObject.create(serialized[customFormId]));
    });
    return deserialized;
  },

  serialize(deserialized) {
    return deserialized;
github hummingbird-me / hummingbird-client / app / transforms / boolean-to-true.js View on Github external
import DS from 'ember-data';

export default DS.Transform.extend({
  deserialize(serialized) {
    return (serialized === null || serialized === undefined) ? true : serialized;
  },

  serialize(deserialized) {
    return deserialized;
  }
});
github hashicorp / vault / ui / app / transforms / integer.js View on Github external
import { isEmpty } from '@ember/utils';
import DS from 'ember-data';

/*
  DS.attr('integer')
*/
export default DS.Transform.extend({
  deserialize: function(value) {
    if (isEmpty(value)) {
      return null;
    } else {
      return value;
    }
  },
  serialize: function(value) {
    if (isEmpty(value)) {
      return null;
    } else {
      return value;
    }
  },
});
github alphasights / ember-scrollable / app / transforms / utc.js View on Github external
import DS from 'ember-data';

export default DS.Transform.extend({
  serialize: function(value) {
    return value ? value.toJSON() : null;
  },

  deserialize: function(value) {
    return moment(value);
  }
});
github HospitalRun / hospitalrun-frontend / app / transforms / operative-procedures.js View on Github external
import { get } from '@ember/object';
import { isEmpty } from '@ember/utils';
import DS from 'ember-data';

export default DS.Transform.extend({

  deserialize(serialized) {
    if (isEmpty(serialized)) {
      return [];
    }
    return serialized.map((description) => {
      return {
        description
      };
    });
  },

  serialize(deserialized) {
    if (isEmpty(deserialized)) {
      return [];
    }