Coder Social home page Coder Social logo

ember-data-sails-adapter's Introduction

ember-data-sails-adapter 2.0

An Ember Data adapter for Sails.js v0.10.

Note: If you like to use this adapter with Sails.js v0.9 please use the 1.x line.

This package contains 2 Adapters, DS.SailsSocketAdapter and DS.SailsRESTAdapter.

bower install ember-data-sails-adapter
<script type="text/javascript" src="/bower_components/ember-data-sails-adapter/ember-data-sails-adapter.js"></script>

SailsSocketAdapter

The SailsSocketAdapter uses Sails's websocket support to find, create and delete records. This has the benifit of automatically subscribing to the Sails' update, create and delete events for for the model. To enable these events with Blueprint controllers in Sails v0.10 you will need to set the autosubscribe property on your Model. The adapter will add or update records in the store when a Sails emits an updated, created or destroyed event.

App.ApplicationAdapter = DS.SailsSocketAdapter.extend({
    namespace: '/api/v1',
});

SailsRESTAdapter

The SailsRESTAdapter works similarly to the Ember RESTAdapter. The main differences are this adapter automatically attempts to use the JSONSerializer instead of the RESTSerializer because it more closely matches the JSON response from Sails. Additionally it will re-format the error messages returned by Sails to match the format that Ember Data expects. With the SailsRESTAdapter you will not get the live updateing that comes with the SailsSocketAdapter. However, because websockets do not support compression using the SailsRESTAdapter may be benificial when you are expecting a large response from the Sails api.

App.ApplicationAdapter = DS.SailsRESTAdapter.extend({
    namespace: '/api/v1'
});

ApplicationSerializer

Unlike, the Serializer from v1.x, in version 2 of ember-data-sails-adapter the the SailsSocketAdapter and SailsRESTAdapter both work best using the RESTSerializer.

App.ApplicationSerializer = DS.RESTSerializer.extend({});

SailsSocketAdapter Options

The options below are for the SailsSocketAdapter. To see a list of options for the SailsRESTAdapter see the RESTAdapter docs.

namespace

Type: String Default value: ''

The prefix to add to the request uris.

log

Type: Boolean Default value: false

Set to true if you would like to see a log of all requests in the command line.

useCSRF

Type: Boolean Default value: false

Used to map lowercase model names that sails uses to model names that ember can understand.

ember-data-sails-adapter 1.x

An Ember Data adapter for Sails.js v0.9.

This package contains 2 Adapters, DS.SailsSocketAdapter and DS.SailsRESTAdapter.

bower install ember-data-sails-adapter#1.0.1
<script type="text/javascript" src="/bower_components/ember-data-sails-adapter/ember-data-sails-adapter.js"></script>

SailsSocketAdapter

The SailsSocketAdapter uses Sails's websocket support to find, create and delete records. This has the benifit of automatically subscribing to the Sails' update, create and delete events for for the model. The adapter will add or update records in the store when a Sails emits an update, create and delete event.

App.ApplicationAdapter = DS.SailsSocketAdapter.extend({
    namespace: '/api/v1',
    log: false,
    modelNameMap: {
      userprofile: 'UserProfile'
    }
});

SailsRESTAdapter

The SailsRESTAdapter works similarly to the Ember RESTAdapter. The main differences are this adapter automatically attempts to use the JSONSerializer instead of the RESTSerializer because it more closely matches the JSON response from Sails. Additionally it will re-format the error messages returned by Sails to match the format that Ember Data expects. With the SailsRESTAdapter you will not get the live updateing that comes with the SailsSocketAdapter. However, because websockets do not support compression using the SailsRESTAdapter may be benificial when you are expecting a large response from the Sails api.

App.ApplicationAdapter = DS.SailsRESTAdapter.extend({
    namespace: '/api/v1'
});

ApplicationSerializer

In Sails v0.9, the SailsSocketAdapter and SailsRESTAdapter both work best using the JSONSerializer. As a result of a bug in the stock JSONSerializer it is recommend that you create an ApplicationSerializer by extending the JSONSerializer like in the example below.

App.ApplicationSerializer = DS.JSONSerializer.extend({
  // Fix broken extractArray see:
  // https://github.com/emberjs/data/pull/1479
  extractArray: function(store, type, arrayPayload) {
    var serializer = this;
    return Ember.ArrayPolyfills.map.call(arrayPayload, function(singlePayload) {
      return serializer.extractSingle(store, type, singlePayload);
    });
  },
  // Allow JSONSerializer to work with RESTAdapter
  // https://github.com/emberjs/data/blob/7e83ed158034cf7fedf2a7113a82de5d5ce67e76/packages/ember-data/lib/adapters/rest_adapter.js#L379
  serializeIntoHash: function(hash, type, record, options) {
    Ember.merge(hash, this.serialize(record, options));
  }
});

SailsSocketAdapter Options

The options below are for the SailsSocketAdapter. To see a list of options for the SailsRESTAdapter see the RESTAdapter docs.

namespace

Type: String Default value: ''

The prefix to add to the request uris.

log

Type: Boolean Default value: false

Set to true if you would like to see a log of all requests in the command line.

modelNameMap

Type: Object Default value: {}

Used to map lowercase model names that sails uses to model names that ember can understand.

License

MIT License

ember-data-sails-adapter's People

Contributors

bmac avatar murcho avatar nmec avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.