New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ember-data-partial-model

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-data-partial-model

Add support for partial models to Ember Data.

0.1.0
Source
npm
Version published
Weekly downloads
19
-87.25%
Maintainers
1
Weekly downloads
 
Created
Source

Ember-data-partial-model

This addon adds support for partial records to Ember Data. Lets say your api for /users returns a shallow model like:

[ { id:1, name: 'BMac'}, {id:2, name:'Seb'}]

but /users/1 returns a detailed model

{ id:1,
  name: 'BMac'
  twitter: 'seb'
}

You can use this addon to define your User model as:

import { PartialModel, partial } from 'ember-data-partial-model/utils/model';
const { attr } = DS;

export default PartialModel.extend({
  name: attr(),
  extended: partial('user', 'extended', {
    twitter: attr()
  })
});

This addon will modify your application adapter/serializer, so that accessing user.get('extended') or any of the extended properties will trigger a request for the detailed model. For example:

let users = await store.find('user'); //goes to /users
let user = users.objectAt(1);

user.get('extended') //goes to /users/1, returns a promise
user.get('twitter') //goes to /users/1, but is just an alias, so returns null initially, should not do in app code

Thus you are safe from race conditions when rendering users, even if you have not loaded the full user In your template you can do

{{user.twitter}}

and it will populate once the full user is loaded

Installation

  • git clone this repository
  • npm install
  • bower install

Running

  • ember server
  • Visit your app at http://localhost:4200.

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.

Keywords

ember-addon

FAQs

Package last updated on 16 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts