Skip to content

Commit 6d3dd5e

Browse files
committed
Some documentation fixes and other chores.
1 parent 8a66f99 commit 6d3dd5e

File tree

12 files changed

+435
-332
lines changed

12 files changed

+435
-332
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
##### 0.10.6 - xx August 2014
1+
##### 1.0.0-beta.1 - xx August 2014
22

33
###### Backwards compatible API changes
4+
- #118, #122 - Multiple relationships to the same model
45
- #120 - When using DSCacheFactory, allow onExpire to be specified
56

7+
###### Other
8+
- #121 - Documentation errors
9+
610
##### 0.10.5 - 14 August 2014
711

812
###### Backwards compatible API changes

CONTRIBUTING.md

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
# Contributing Guide
22

3-
First, feel free to contact me with questions
3+
First, feel free to contact me with questions. [Mailing List](https://groups.google.com/forum/?fromgroups#!forum/angular-data). [Issues](https://github.com/jmdobry/angular-data/issues).
44

5-
1. Fork the repo
6-
- `$ git clone <yourForkUrl>`
7-
- `$ npm install && bower install && npm test`
8-
1. Checkout a new branch based on whatever version branch is available (if none then branch from `master`) and name it to what you intend to do:
9-
- `$ git checkout -b BRANCH_NAME`
10-
- Use one branch per fix/feature
11-
1. Make your changes
12-
- Use `grunt build`, `grunt watch` and `grunt karma:dev` while developing
13-
- Make sure to provide a spec for unit tests
14-
- Run your tests with `test`
15-
- When all tests pass, everything's fine
16-
1. Commit your changes
17-
- Please provide a git message which explains what you've done
18-
- Commit to the forked repository
19-
1. Make a pull request
20-
- Make sure you send the PR to the branch you branched from
21-
- Travis CI is watching you!
5+
1. Contribute to the issue that is the reason you'll be developing in the first place
6+
1. Fork angular-data
7+
1. `git clone https://github.com/<you>/angular-data.git`
8+
1. `cd angular-data; npm install; bower install;`
9+
1. `grunt go` (builds and starts a watch)
10+
1. (in another terminal) `grunt karma:dev` (runs the tests)
11+
1. Write your code, including relevant documentation and tests
12+
1. Submit a PR and we'll review

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
module.exports = function (grunt) {
99
'use strict';
1010

11-
require('load-grunt-tasks')(grunt);
11+
require('jit-grunt')(grunt);
1212
require('time-grunt')(grunt);
1313

1414
var dev = process.cwd().indexOf('/home/jdobry/angular-data') === -1;

README.md

Lines changed: 74 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,71 @@
11
## angular-data
22

3-
__Data store for Angular.js.__
3+
Inspired by [Ember Data](https://github.com/emberjs/data), Angular-data is the model layer Angular is missing. It consists of a convenient in-memory cache for interacting with your various resources, and several adapters for communicating with various persistence layers.
4+
5+
By default angular-data uses the http adapter–perfect for communicating with your RESTful backend. It includes a localStorage adapter, and another [localforage adapter](https://github.com/jmdobry/angular-data-localForage) is also available. More adapters are coming, and you're free to implement your own.
6+
7+
Unlike Backbone and Ember Models, angular-data does not require the use of getters and setters, and doesn't wrap your data with custom classes if you don't want it to. Angular-data's internal dirty-checking (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).
8+
9+
Supporting relations, computed properties, model lifecycle control and a slew of other features, angular-data is the tool for giving your data the respect it deserves.
410

511
__Latest Release:__ [0.10.5](http://angular-data.pseudobry.com/)
6-
__master:__ [0.10.6](http://angular-data-next.pseudobry.com/)
12+
__master:__ [1.0.0-beta.1](http://angular-data-next.pseudobry.com/)
713

814
Angular-data is approaching 1.0.0 Beta. The API is stabilizing and angular-data is well tested.
915

10-
Angular-data is being used in production, though it's not 1.0.0. If you want to use Angular-data, keep an eye on the changelog. 1.0.0 will introduce strict semver (until then, minor number is bumped for breaking changes).
16+
Although angular-data is being used in production, it's not 1.0.0. If you want to use Angular-data, keep an eye on the changelog. 1.0.0 will introduce strict semver (until then, minor number is bumped for breaking changes).
1117

12-
Roadmap:
13-
- Even more adapters
14-
- Nested Resources
15-
- See [issues](https://github.com/jmdobry/angular-data/issues?page=1&state=open) for what's in development
16-
- See [Design Doc](https://docs.google.com/document/d/1o069KLuBH4jpwm1FCLZFwKMgM73Xi8_1JyjhSxVpidM/edit?usp=sharing) for other juicy reading material
1718

1819
## Documentation
19-
[angular-data.pseudobry.com](http://angular-data.pseudobry.com)
20+
[http://angular-data.pseudobry.com](http://angular-data.pseudobry.com)
21+
22+
## Quick Start
23+
`bower install angular-data` or `npm install angular-data`.
24+
25+
```js
26+
var app = angular.module('myApp', ['angular-data.DS']);
27+
```
28+
29+
```js
30+
app.factory('User', function (DS) {
31+
// Simplest resource definition
32+
return DS.defineResource('user');
33+
});
34+
```
35+
36+
```js
37+
app.controller('friendsCtrl', function ($scope, $routeParams, User) {
38+
// it's up to your server to know how to interpret this query
39+
// or you can teach angular-data how to understand your servers' query language
40+
var query = {
41+
where: {
42+
friendIds: {
43+
in: $routeParams.id
44+
}
45+
}
46+
};
47+
48+
User.find($routeParams.id);
49+
User.findAll(query);
50+
51+
// My goodness this was easy
52+
User.bindOne($scope, 'me', $routeParams.id);
53+
User.bindAll($scope, 'friends', query);
54+
55+
// Long form
56+
$scope.$watch(function () {
57+
return User.lastModified($routeParams.id);
58+
}, function () {
59+
$scope.me = User.get($routeParams.id);
60+
});
61+
$scope.$watch(function () {
62+
// Changes when anything in the User collection is modified
63+
return User.lastModified();
64+
}, function () {
65+
$scope.friends = User.filter(query);
66+
});
67+
});
68+
```
2069

2170
## Changelog
2271
[CHANGELOG.md](https://github.com/jmdobry/angular-data/blob/master/CHANGELOG.md)
@@ -35,7 +84,7 @@ Roadmap:
3584

3685
[Design Doc](https://docs.google.com/document/d/1o069KLuBH4jpwm1FCLZFwKMgM73Xi8_1JyjhSxVpidM/edit?usp=sharing) - Design document for Angular-data.
3786

38-
[Contributing Guide](https://github.com/jmdobry/angular-data/blob/master/CONTRIBUTING.md)
87+
[Contributing Guide](#Contributing)
3988

4089
## Project Status
4190

@@ -48,6 +97,21 @@ Roadmap:
4897
| Dependency Status | [![Dependency Status](https://gemnasium.com/jmdobry/angular-data.png)](https://gemnasium.com/jmdobry/angular-data) |
4998
| Coverage | [![Coverage Status](https://coveralls.io/repos/jmdobry/angular-data/badge.png?branch=master)](https://coveralls.io/r/jmdobry/angular-data?branch=master) |
5099

100+
## Contributing
101+
102+
First, feel free to contact me with questions. [Mailing List](https://groups.google.com/forum/?fromgroups#!forum/angular-data). [Issues](https://github.com/jmdobry/angular-data/issues).
103+
104+
1. Contribute to the issue that is the reason you'll be developing in the first place
105+
1. Fork angular-data
106+
1. `git clone https://github.com/<you>/angular-data.git`
107+
1. `cd angular-data; npm install; bower install;`
108+
1. `grunt go` (builds and starts a watch)
109+
1. (in another terminal) `grunt karma:dev` (runs the tests)
110+
1. Write your code, including relevant documentation and tests
111+
1. Submit a PR and we'll review
112+
113+
## License
114+
51115
Copyright (C) 2014 Jason Dobry
52116

53117
Permission is hereby granted, free of charge, to any person obtaining a copy of

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "Jason Dobry",
33
"name": "angular-data",
44
"description": "Data store for Angular.js.",
5-
"version": "0.10.6",
5+
"version": "1.0.0-beta.1",
66
"homepage": "http://angular-data.pseudobry.com/",
77
"repository": {
88
"type": "git",

dist/angular-data.js

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @author Jason Dobry <jason.dobry@gmail.com>
33
* @file angular-data.js
4-
* @version 0.10.6 - Homepage <http://angular-data.pseudobry.com/>
4+
* @version 1.0.0-beta.1 - Homepage <http://angular-data.pseudobry.com/>
55
* @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/>
66
* @license MIT <https://github.com/jmdobry/angular-data/blob/master/LICENSE>
77
*
@@ -1459,8 +1459,8 @@ function DSHttpAdapterProvider() {
14591459
*
14601460
* ## Example:
14611461
* ```js
1462-
* angular.module('myApp', function (DSHttpAdapterProvider) {
1463-
* angular.extend(DSHttpAdapterProvider.defaults.httpConfig, {
1462+
* angular.module('myApp').config(function (DSHttpAdapterProvider) {
1463+
* angular.extend(DSHttpAdapterProvider.defaults.$httpConfig, {
14641464
* interceptor: [...],
14651465
* headers: {
14661466
* common: {
@@ -2839,30 +2839,36 @@ function loadRelations(resourceName, instance, relations, options) {
28392839
var tasks = [];
28402840
var fields = [];
28412841

2842-
DS.utils.forOwn(definition.relations, function (relation, type) {
2843-
DS.utils.forOwn(relation, function (def, relationName) {
2844-
if (DS.utils.contains(relations, relationName)) {
2845-
var task;
2846-
var params = {};
2847-
params[def.foreignKey] = instance[definition.idAttribute];
2848-
2849-
if (type === 'hasMany') {
2850-
task = DS.findAll(relationName, params, options);
2851-
} else if (type === 'hasOne') {
2852-
if (def.localKey && instance[def.localKey]) {
2853-
task = DS.find(relationName, instance[def.localKey], options);
2854-
} else if (def.foreignKey) {
2842+
DS.utils.forOwn(definition.relations, function (relatedModels, type) {
2843+
DS.utils.forOwn(relatedModels, function (defs, relationName) {
2844+
if (!DS.utils.isArray(defs)) {
2845+
defs = [defs];
2846+
}
2847+
2848+
defs.forEach(function (def) {
2849+
if (DS.utils.contains(relations, relationName)) {
2850+
var task;
2851+
var params = {};
2852+
params[def.foreignKey] = instance[definition.idAttribute];
2853+
2854+
if (type === 'hasMany') {
28552855
task = DS.findAll(relationName, params, options);
2856+
} else if (type === 'hasOne') {
2857+
if (def.localKey && instance[def.localKey]) {
2858+
task = DS.find(relationName, instance[def.localKey], options);
2859+
} else if (def.foreignKey) {
2860+
task = DS.findAll(relationName, params, options);
2861+
}
2862+
} else {
2863+
task = DS.find(relationName, instance[def.localKey], options);
28562864
}
2857-
} else {
2858-
task = DS.find(relationName, instance[def.localKey], options);
2859-
}
28602865

2861-
if (task) {
2862-
tasks.push(task);
2863-
fields.push(def.localField);
2866+
if (task) {
2867+
tasks.push(task);
2868+
fields.push(def.localField);
2869+
}
28642870
}
2865-
}
2871+
});
28662872
});
28672873
});
28682874

@@ -5362,15 +5368,21 @@ function _inject(definition, resource, attrs) {
53625368

53635369
function _injectRelations(definition, injected) {
53645370
var DS = this;
5365-
DS.utils.forOwn(definition.relations, function (relation, type) {
5366-
DS.utils.forOwn(relation, function (def, relationName) {
5367-
if (DS.definitions[relationName] && injected[def.localField]) {
5368-
try {
5369-
injected[def.localField] = DS.inject(relationName, injected[def.localField]);
5370-
} catch (err) {
5371-
DS.$log.error(errorPrefix(definition.name) + 'Failed to inject ' + type + ' relation: "' + relationName + '"!', err);
5372-
}
5371+
DS.utils.forOwn(definition.relations, function (relatedModels, type) {
5372+
DS.utils.forOwn(relatedModels, function (defs, relationName) {
5373+
if (!DS.utils.isArray(defs)) {
5374+
defs = [defs];
53735375
}
5376+
5377+
defs.forEach(function (def) {
5378+
if (DS.definitions[relationName] && injected[def.localField]) {
5379+
try {
5380+
injected[def.localField] = DS.inject(relationName, injected[def.localField]);
5381+
} catch (err) {
5382+
DS.$log.error(errorPrefix(definition.name) + 'Failed to inject ' + type + ' relation: "' + relationName + '"!', err);
5383+
}
5384+
}
5385+
});
53745386
});
53755387
});
53765388
}
@@ -5764,7 +5776,7 @@ module.exports = [function () {
57645776
* @id angular-data
57655777
* @name angular-data
57665778
* @description
5767-
* __Version:__ 0.10.0
5779+
* __Version:__ 1.0.0-beta.1
57685780
*
57695781
* ## Install
57705782
*
@@ -5783,7 +5795,7 @@ module.exports = [function () {
57835795
* Load `dist/angular-data.js` or `dist/angular-data.min.js` onto your web page after Angular.js.
57845796
*
57855797
* #### Manual download
5786-
* Download angular-data-<%= pkg.version %>.js from the [Releases](https://github.com/jmdobry/angular-data/releases)
5798+
* Download angular-data from the [Releases](https://github.com/jmdobry/angular-data/releases)
57875799
* section of the angular-data GitHub project.
57885800
*
57895801
* ## Load into Angular

dist/angular-data.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

guide/angular-data/resource/resource.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,18 @@ DS.defineResource({
311311
name: 'organization',
312312
relations: {
313313
hasMany: {
314-
user: {
315-
localField: 'users',
316-
foreignKey: 'organizationId'
317-
}
314+
// this is an example of multiple relations
315+
// of the same type to the same resource
316+
user: [
317+
{
318+
localField: 'users',
319+
foreignKey: 'organizationId'
320+
},
321+
{
322+
localField: 'owners',
323+
foreignKey: 'organizationId'
324+
}
325+
]
318326
}
319327
}
320328
});
@@ -344,7 +352,7 @@ DS.defineResource({
344352
});
345353
```
346354
347-
`DS.inject` can be called by you, and is also used internally by `find`, `findAll`, `create`, `update`, `updateAll`, `save` and `refresh`.
355+
You can manually load items into the data store via `DS.inject`.
348356
349357
## Loading relations
350358
@@ -426,7 +434,7 @@ DS.defineResource('user', {
426434
// you computed properties to work after you've
427435
// minified your code
428436
initials: function (first, last) {
429-
return first.toUppercase()[0] + '. ' + last.toUppercase()[0] + '.';
437+
return first.toUppercase()[0] + '. ' + last.toUppercase()[0] + '.';
430438
}
431439
}
432440
});

0 commit comments

Comments
 (0)