How to use the ember-data/transform.extend 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 TryGhost / Ghost-Admin / app / transforms / mailchimp-settings.js View on Github external
/* eslint-disable camelcase */
import Transform from 'ember-data/transform';
import {getOwner} from '@ember/application';

export default Transform.extend({
    deserialize(serialized) {
        let settings = {};

        if (serialized) {
            try {
                settings = JSON.parse(serialized) || {};
            } catch (e) {
                settings = {};
            }
        }

        let factory = getOwner(this).factoryFor('object:mailchimp-integration');
        return factory.create(settings);

    },
github lytics / ember-data-model-fragments / addon / transforms / fragment.js View on Github external
import { assert } from '@ember/debug';
import { get } from '@ember/object';
import Transform from 'ember-data/transform';
import JSONAPISerializer from 'ember-data/serializers/json-api';

/**
  Transform for `MF.fragment` fragment attribute which delegates work to
  the fragment type's serializer

  @class FragmentTransform
  @namespace MF
  @extends DS.Transform
*/
const FragmentTransform = Transform.extend({
  store: null,
  type: null,
  polymorphicTypeProp: null,

  deserialize: function deserializeFragment(data) {
    if (data == null) {
      return null;
    }

    return this.deserializeSingle(data);
  },

  serialize: function serializeFragment(snapshot) {
    if (!snapshot) {
      return null;
    }
github hummingbird-me / hummingbird-client / app / transforms / array.js View on Github external
import { isArray } from '@ember/array';
import Transform from 'ember-data/transform';

export default Transform.extend({
  deserialize(value) {
    return isArray(value) ? value : [];
  },

  serialize(value) {
    return this.deserialize(value);
  }
});
github funtusov / ember-cli-form-data / app / transforms / file.js View on Github external
import Transform from 'ember-data/transform';

export default Transform.extend({
  deserialize: function(serialized) {
    return serialized;
  },

  serialize: function(deserialized) {
    return deserialized;
  }
});
github TryGhost / Ghost-Admin / app / transforms / raw.js View on Github external
import Transform from 'ember-data/transform';

export default Transform.extend({
    deserialize(serialized) {
        return serialized;
    },

    serialize(deserialized) {
        return deserialized;
    }
});
github TryGhost / Ghost-Admin / app / transforms / navigation-settings.js View on Github external
import NavigationItem from 'ghost-admin/models/navigation-item';
import Transform from 'ember-data/transform';
import {A as emberA, isArray as isEmberArray} from '@ember/array';

export default Transform.extend({
    deserialize(serialized, options) {
        let navItems, settingsArray;

        try {
            settingsArray = JSON.parse(serialized) || [];
        } catch (e) {
            settingsArray = [];
        }

        navItems = settingsArray.map((itemDetails) => {
            itemDetails.isSecondary = options && options.isSecondary || false;
            return NavigationItem.create(itemDetails);
        });

        return emberA(navItems);
    },
github fossasia / open-event-frontend / app / transforms / moment.js View on Github external
import Transform from 'ember-data/transform';
import moment from 'moment';

export default Transform.extend({
  deserialize(serialized) {
    if (!serialized) {
      return null;
    }
    return moment(serialized);
  },

  serialize(deserialized) {
    if (!deserialized) {
      return null;
    }
    return moment(deserialized).toISOString();
  }
});
github hummingbird-me / hummingbird-client / app / transforms / rating.js View on Github external
import Transform from 'ember-data/transform';

export default Transform.extend({
  deserialize(value) {
    return value / 2;
  },

  serialize(value) {
    return value * 2 || null;
  }
});
github lytics / ember-data-model-fragments / addon / transforms / array.js View on Github external
import { assert } from '@ember/debug';
import { getOwner } from '@ember/application';
import { makeArray } from '@ember/array';
import { get, computed } from '@ember/object';
import Transform from 'ember-data/transform';

/**
  Transform for `MF.array` that transforms array data with the given transform
  type.

  @class ArrayTransform
  @namespace MF
  @extends DS.Transform
*/
const ArrayTransform = Transform.extend({
  store: null,
  type: null,

  deserialize: function deserializeArray(data) {
    if (data == null) {
      return null;
    }

    let transform = get(this, 'transform');

    data = makeArray(data);

    if (!transform) {
      return data;
    }
github TryGhost / Ghost-Admin / app / transforms / moment-date.js View on Github external
import Transform from 'ember-data/transform';
import moment from 'moment';

export default Transform.extend({
    deserialize(serialized) {
        if (serialized) {
            return moment(serialized);
        }
        return serialized;
    },

    serialize(deserialized) {
        if (deserialized) {
            return moment(deserialized).toDate();
        }
        return deserialized;
    }
});