Skip to content

Commit 934699f

Browse files
committed
Closes #124.
Stable Version 1.0.0-beta.1
1 parent e16e0cd commit 934699f

File tree

9 files changed

+113
-25
lines changed

9 files changed

+113
-25
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
##### 1.0.0-beta.1 - xx August 2014
1+
##### 1.0.0-beta.1 - 23 August 2014
22

33
###### Backwards compatible API changes
44
- #40 - Support for nested resource endpoints

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ Supporting relations, computed properties, model lifecycle control and a slew of
1111
__Latest Release:__ [0.10.5](http://angular-data.pseudobry.com/)
1212
__master:__ [1.0.0-beta.1](http://angular-data-next.pseudobry.com/)
1313

14-
Angular-data is approaching 1.0.0 Beta. The API is stabilizing and angular-data is well tested.
15-
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).
14+
Angular-data is in a 1.0.0 Beta. The API is rather stable and angular-data is well tested.
1715

16+
Although angular-data is being used in production, it's not fully 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).
1817

1918
## Documentation
2019
[http://angular-data.pseudobry.com](http://angular-data.pseudobry.com)

bower.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
"karma.start.js"
2727
],
2828
"devDependencies": {
29-
"angular": "~1.2.16",
30-
"angular-mocks": "~1.2.16",
29+
"angular": "~1.2.22",
30+
"angular-mocks": "~1.2.22",
3131
"angular-cache": "~3.1.0",
3232
"observe-js": "0.3.4",
33-
"angular-data-mocks": "~0.5.3",
33+
"angular-data-mocks": "~0.5.5",
3434
"bootstrap": "~3.2.0"
3535
}
3636
}

guide/angular-data/asynchronous.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
@name Asynchronous Methods
44
@description
55

6-
Angular-data ships with a number of asynchronous methods that facilitate communication between the data store and the
7-
persistence layer. These methods cover the basic CRUD operations.
6+
Angular-data ships with a number of asynchronous methods that facilitate communication between the data store and a
7+
persistence layer. These methods cover CRUD operations.
88

99
The asynchronous methods return Promises produced by Angular's `$q` service.
1010

1111
Example:
1212

1313
```js
14-
// synchronous
14+
// synchronous, looks only at the cache
1515
DS.get('document', 45); // undefined
1616

17-
// asynchronous
17+
// asynchronous, works through an adapter
1818
DS.find('document', 45).then(function (document) {
1919
document; // { title: 'How to Cook', id: 45 }
2020

guide/angular-data/how.md

+75-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
@name How do I?
44
@description
55

6-
#### How do I serialize data before it's saved?
7-
Before the data store sends date to an adapter, you may need to transform it to a custom request object of yours.
6+
## How do I serialize data before it's saved?
7+
Before the data store sends data to an adapter, you may need to transform it into a custom request object of yours.
88

99
Define a global serialization method:
1010
```js
@@ -28,8 +28,8 @@ DS.defineResource({
2828
});
2929
```
3030

31-
#### How do I deserialize data?
32-
When an adapter returns data to the data store from the server, for example, you may need to extract data from a custom response object of yours.
31+
## How do I deserialize data?
32+
When an adapter returns data to the data store from a persistence layer, you may need to extract data from a custom response object of yours.
3333

3434
Define a global deserialization method:
3535
```js
@@ -48,3 +48,74 @@ DS.defineResource({
4848
}
4949
});
5050
```
51+
52+
## How do I use angular-cache with angular-data?
53+
54+
First, make sure you have angular-data.js and angular-cache.js loaded and your app has `angular-data.DS` and `angular-data.DSCacheFactory` as dependencies.
55+
56+
Each resource you define will have its own cache instance, so you can pass different options to each resource.
57+
58+
```js
59+
var Document = DS.defineResource({
60+
name: 'document',
61+
maxAge: 900000,
62+
deleteOnExpire: 'aggressive'
63+
});
64+
65+
var User = DS.defineResource({
66+
name: 'user',
67+
maxAge: 36000000,
68+
deleteOnExpire: 'aggressive',
69+
onExpire: function (id, user) {...}
70+
});
71+
```
72+
73+
## How do I add my own static methods to resources?
74+
75+
```js
76+
app.factory('User', function (DS, $q) {
77+
78+
var loggedInUser;
79+
80+
var User = DS.defineUser({
81+
name: 'user',
82+
methods: {
83+
// Instance method
84+
fullName: function () {
85+
return this.first + ' ' + this.last;
86+
}
87+
}
88+
});
89+
90+
// Static method
91+
User.getLoggedInUser = function () {
92+
var deferred = $q.defer();
93+
94+
if (loggedInUser) {
95+
deferred.resolve(loggedInUser);
96+
} else {
97+
DS.find('loggedInUser', { cacheResponse: false })
98+
.then(function (user) {
99+
loggedInUser = user;
100+
deferred.resolve(loggedInUser);
101+
}, deferred.reject);
102+
}
103+
104+
return deferred.promise;
105+
};
106+
107+
return User;
108+
});
109+
```
110+
111+
```js
112+
app.controller('ProfileCtrl', function (User) {
113+
114+
// use the static method
115+
User.getLoggedInUser().then(function (user) {
116+
117+
// instance methods would be used here
118+
user.fullName(); // "John Anderson"
119+
});
120+
});
121+
```

guide/angular-data/resource/resource.md

+19-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@name Overview
1313
@description
1414

15-
A _resource_ is the data and meta data associated with a particular RESTful endpoint.
15+
An angular-data _resource_ is the data and meta data associated with a particular RESTful resource.
1616

1717
You define _resources_ and register them with the data store. A _resource definition_ tells angular-data
1818
about a particular _resource_, like what its root endpoint is and which attribute refers to the primary key of the
@@ -48,6 +48,10 @@ With this definition the data store assumes the following:
4848
- The RESTful endpoint for this resource is `DSProvider.defaults.baseUrl + "/document"`
4949
- The primary key is specified by the `"id"` property (or whatever is specified by `DSProvider.defaults.idAttribute`)
5050
- This resource has no custom lifecycle hooks (unless `DSProvider.defaults` has some lifecycle hooks defined)
51+
- No computed properties
52+
- No instance methods
53+
- No extra configuration for angular-cache (if you have it loaded)
54+
- No relations
5155

5256
@doc overview
5357
@id advanced
@@ -62,16 +66,26 @@ var Document = DS.defineResource({
6266
idAttribute: '_id',
6367
endpoint: 'documents',
6468
baseUrl: 'https://example.com/api',
69+
70+
// hook for the validate step in the model lifecycle
6571
validate: function (attrs, cb) {
6672
if (!angular.isObject(attrs) {
6773
cb('Must be an object!');
6874
} else if (!angular.isString(attrs.title)) {
6975
cb('title must be a string!');
7076
}
7177
},
78+
7279
// the "meta" property is reserved for developer use
7380
// it will never be used by the API
74-
meta: {}
81+
meta: {},
82+
83+
// instance methods
84+
methods: {
85+
filename: function () {
86+
return this.title + '.' + this.extension;
87+
}
88+
}
7589
});
7690
```
7791
@@ -80,7 +94,8 @@ With this definition the data store understands the following:
8094
- Resource will be referred to as `"document"`
8195
- The RESTful endpoint for this resource is `"https://example.com/api/documents"`
8296
- The primary key is specified by the `"_id"` property
83-
- Before create/save operations, the provided `validate` function is executed (and any lifecycle hooks defined in `DSProvider.defaults`)
97+
- Before create/update operations, the provided `validate` function is executed (and any lifecycle hooks defined in `DSProvider.defaults`)
98+
- documents will have one instance method
8499
85100
See [DS.defineResource](/documentation/api/api/DS.sync_methods:defineResource) for the full resource definition specification.
86101
@@ -100,7 +115,7 @@ The following asynchronous operations support a model lifecycle:
100115
- `create` - Implementation provided by adapter
101116
- `afterCreate` - Default: `noop`
102117
103-
### DS.save()
118+
### DS.save() & DS.update()
104119
105120
- `beforeValidate` - Default: `noop`
106121
- `validate` - Default: `noop`

guide/angular-data/resources.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ Angular-data keeps track of _resource definitions_ to know what kind of data sho
99
myApp.run(function (DS) {
1010

1111
// This is a basic resource definition
12-
DS.defineResource({
12+
var Document = DS.defineResource({
1313
name: 'document'
1414
});
1515

1616
// angular-data now knows it can perform
1717
// operations related to the "document" resource
18+
19+
// These are the same
20+
Document.find(5).then(function (document) {...});
21+
DS.find('document', 5).then(function (document) {...});
1822
});
1923
```
2024

guide/angular-data/synchronous.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Example:
1313
DS.get('document', 45); // { title: 'How to Cook', id: 45 }
1414
```
1515

16-
`get(resourceName, id)` will return the data if it is in the store, otherwise `undefined`. This method is useful inside
16+
`get(resourceName, id[ options])` will return the data if it is in the store, otherwise `undefined`. This method is useful inside
1717
of a `$watch` callback function, for example:
1818

1919
```js
@@ -33,6 +33,7 @@ To make things simpler, angular-data has some bind methods to help with this:
3333

3434
```js
3535
DS.bindOne($scope, 'myDoc', 'document', 45');
36+
Document.bindOne($scope, 'myDoc', 45');
3637
```
3738

3839
The above example shows how to bind an item in the data store to the $scope. Whenever that item changes it will be updated

guide/index.html

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
<head>
77
<meta charset="utf-8">
88
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
9-
<meta name="Description"
10-
content="An in-browser data store for Angular.js.">
11-
<meta name="Keywords"
12-
content="model, schema, angular, angular.js, data, datastore, adapter, store">
9+
<meta name="Description" content="Data store and caching for Angular.js.">
10+
<meta name="Keywords" content="model, schema, angular, angular.js, data, datastore, adapter, store">
1311
<meta name="fragment" content="!">
1412
<meta name="google-site-verification" content="k4PBv7ljh_CWjOj3OwgNdB3dlnD1DFUiLZjoovga2so" />
1513
<title ng-bind-template="angular-data: {{mainpage.partialTitle}}">angular-data</title>

0 commit comments

Comments
 (0)