|
2 | 2 |
|
3 | 3 | ## JSData [](https://gitter.im/js-data/js-data?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [](https://www.npmjs.org/package/js-data) [](https://www.npmjs.org/package/js-data) [](https://circleci.com/gh/js-data/js-data/tree/master) [](https://www.npmjs.org/package/js-data) [](https://github.com/js-data/js-data/blob/master/LICENSE)
|
4 | 4 |
|
5 |
| -Inspired by [Ember Data](https://github.com/emberjs/data), __JSData__ is the model layer you've been craving. It consists of a convenient __framework-agnostic, in-memory store__ for managing your data, which uses __adapters__ to communicate with various __persistence layers__. |
| 5 | +Inspired by [Ember Data](https://github.com/emberjs/data), __JSData__ is the model layer you've been craving. It consists of a convenient __framework-agnostic__, __in-memory store__ for managing your data, which uses __adapters__ to communicate with various __persistence layers__. |
6 | 6 |
|
7 |
| -You can use the [http adapter](http://www.js-data.io/docs/dshttpadapter), which is perfect for communicating with your RESTful backend. You could
8000
also use the [localStorage adapter](http://www.js-data.io/docs/dslocalstorageadapter). On the server you could hook up to the [SQL adapter (Postgres/MySQL/MariaDB/SQLite3)](http://www.js-data.io/docs/dssqladapter) and add in the [Redis adapter](http://www.js-data.io/docs/dsredisadapter) as a caching layer for your read endpoints. More adapters are coming, and you're free to implement your own. View [available adapters](http://www.js-data.io/docs/working-with-adapters). |
| 7 | +The most commonly used adapter is the [http adapter](http://www.js-data.io/docs/dshttpadapter), which is perfect for communicating with your RESTful backend. [localStorage](http://www.js-data.io/js-data-localstorage), [localForage](http://www.js-data.io/js-data-localforage), [firebase](http://www.js-data.io/js-data-firebase) and [other adapters](http://www.js-data.io/docs/working-with-adapters) are already available. On the server you could hook up to the [SQL adapter (Postgres/MySQL/MariaDB/SQLite3)](http://www.js-data.io/docs/dssqladapter) and add in the [Redis adapter](http://www.js-data.io/docs/dsredisadapter) as a caching layer for your read endpoints. More adapters are coming, and you're free to implement your own. See [Adapters](http://www.js-data.io/docs/working-with-adapters). |
8 | 8 |
|
9 | 9 | Unlike some libraries, JSData does not require the use of getters and setters, and doesn't decorate your data with a bunch of cruft. JSData's internal change detection (via [observe-js](https://github.com/Polymer/observe-js) or `Object.observe` in supporting browsers) allows for powerful use cases and an easy avenue for implementing your own [3-way data-binding](https://www.firebase.com/blog/2013-10-04-firebase-angular-data-binding.html).
|
10 | 10 |
|
11 |
| -Supporting relations, computed properties, model lifecycle control and a slew of other features, JSData is the tool for [giving your data the respect it deserves](http://confreaks.tv/videos/mwjs2015-give-your-data-the-respect-it-deserves). |
| 11 | +Supporting relations, computed properties, support for Node and the Browser, model lifecycle control and a slew of other features, JSData is the tool for [giving your data the respect it deserves](http://confreaks.tv/videos/mwjs2015-give-your-data-the-respect-it-deserves). |
12 | 12 |
|
13 | 13 | Written in ES6 and built for modern web development, JSData will save you thousands of lines of code _and_ make you cooler.
|
14 | 14 |
|
@@ -41,9 +41,28 @@ var store = new JSData.DS();
|
41 | 41 | // register and use http by default for async operations
|
42 | 42 | store.registerAdapter('http', new DSHttpAdapter(), { default: true });
|
43 | 43 |
|
44 |
| -// simplest model definition |
| 44 | +// simplest model definition, just pass the name instead of an options hash |
| 45 | +// this is the same as "store.defineResource({ name: 'user' })" |
45 | 46 | var User = store.defineResource('user');
|
46 |
| -var Comment = store.defineResource('comment'); |
| 47 | + |
| 48 | +// Usually you'll define a resource by passing options |
| 49 | +var Comment = store.defineResource({ |
| 50 | + name: 'comment', |
| 51 | + relations: { |
| 52 | + belongsTo: { |
| 53 | + user: { |
| 54 | + // "join" field, name of field on a comment |
| 55 | + // that is the primary key of the parent user |
| 56 | + localKey: 'userId', |
| 57 | + |
| 58 | + // name of the field on the comment where the |
| 59 | + // parent user will be attached to the comment |
| 60 | + // by js-data |
| 61 | + localField: 'user' |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | +}); |
47 | 66 |
|
48 | 67 | var user;
|
49 | 68 |
|
|
0 commit comments