Skip to content

Commit 8895040

Browse files
committed
Various improvements.
1 parent 5ff48a6 commit 8895040

File tree

14 files changed

+137
-24
lines changed

14 files changed

+137
-24
lines changed

Gruntfile.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,17 @@ module.exports = function (grunt) {
239239
storage: 5
240240
}
241241
},
242+
{
243+
id: 'angular-data-mocks',
244+
title: 'angular-data-mocks',
245+
docs: ['guide/angular-data-mocks/'],
246+
rank: {
247+
index: 1,
248+
overview: 2,
249+
setup: 3,
250+
testing: 4
251+
}
252+
},
242253
{
243254
id: 'angular-data-resource',
244255
title: 'Defining Resources',
@@ -248,7 +259,8 @@ module.exports = function (grunt) {
248259
overview: 2,
249260
basic: 3,
250261
advanced: 4,
251-
lifecycle: 5
262+
lifecycle: 5,
263+
custom: 6
252264
}
253265
},
254266
{

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"devDependencies": {
2929
"angular": "~1.2.16",
3030
"angular-mocks": "~1.2.16",
31-
"angular-data-mocks": "0.2.0",
3231
"angular-cache": "~3.0.0-beta.4",
33-
"observe-js": "~0.2.0"
32+
"observe-js": "~0.2.0",
33+
"angular-data-mocks": "~0.3.1"
3434
}
3535
}

dist/angular-data.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3956,7 +3956,15 @@ function _inject(definition, resource, attrs) {
39563956
item = this.get(definition.name, id);
39573957

39583958
if (!item) {
3959-
item = definition.class ? new definition[definition.class]() : {};
3959+
if (definition.class) {
3960+
if (attrs instanceof definition[definition.class]) {
3961+
item = attrs;
3962+
} else {
3963+
item = new definition[definition.class]();
3964+
}
3965+
} else {
3966+
item = {};
3967+
}
39603968
resource.previousAttributes[id] = {};
39613969

39623970
_this.utils.deepMixIn(item, attrs);

dist/angular-data.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

guide/angular-data-mocks/index.doc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@doc overview
2+
@id index
3+
@name Overview
4+
@description
5+
6+
# Overview
7+
8+
<page-list></page-list>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@doc overview
2+
@id overview
3+
@name Overview
4+
@description
5+
6+
Angular-data is a fake angular-data implementation suitable for unit testing angular applications that use the `angular-data.DS` module.
7+
8+
__Version:__ 0.3.0
9+
10+
__angular-data-mocks requires [sinon](http://sinonjs.org/) to be loaded in order to work.__
11+
12+
Refer to the [angular-data-mocks API](/documentation/api/angular-data-mocks/angular-data-mocks) for more detailed information.

guide/angular-data-mocks/setup.doc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@doc overview
2+
@id setup
3+
@name Setting Up
4+
@description
5+
6+
TODO: Explain how to set up angular tests to use angular-data-mocks.
7+
8+
Refer to the [angular-data-mocks API](/documentation/api/angular-data-mocks/angular-data-mocks) for more detailed information.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@doc overview
2+
@id testing
3+
@name Testing
4+
@description
5+
6+
TODO: Explain how to use angular-data-mocks in angular tests.
7+
8+
Refer to the [angular-data-mocks API](/documentation/api/angular-data-mocks/angular-data-mocks) for more detailed information.

guide/angular-data.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
body {
22
background-size: auto;
33
background: url(/resources/img/cream_dust.png) repeat repeat;
4-
font-family:'Open sans',Arial,Helvetica,sans-serif;
4+
font-family: 'Open sans', Arial, Helvetica, sans-serif;
55
}
66

77
.main-nav {
88
border-bottom: 2px solid #0088cc;
99
}
1010

11+
.main-nav .dropdown-menu {
12+
min-width: 250px;
13+
}
14+
1115
.main-nav:before {
1216
content: " ";
1317
position: absolute;

guide/angular-data/resource/resource.doc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,33 @@ angular.module('myApp', ['angular-data.DS'])
167167

168168
});
169169
```
170+
171+
@doc overview
172+
@id custom
173+
@name Custom Model Behavior
174+
@description
175+
176+
If you provide a `methods` field in the options passed to `DS.defineResource`, angular-data wrap items of that resource
177+
with an empty constructor function. The `methods` option should be an object where the keys are method names and the
178+
values are functions. This object will be mixed in to the prototype empty constructor function used to wrap items of the
179+
new resource. In this way you can add custom behavior to what will now be "instances" of the new resource.
180+
181+
## Example:
182+
```js
183+
DS.defineResource({
184+
name: 'user',
185+
methods: {
186+
fullName: function () {
187+
return this.first + ' ' + this.last;
188+
}
189+
}
190+
});
191+
192+
DS.inject('user', { id: 1, first: 'John', last: 'Anderson' });
193+
194+
var user = DS.get('user', 1);
195+
196+
user.fullName(); // "John Anderson"
197+
198+
user.constructor; // function User() { ... }
199+
```

0 commit comments

Comments
 (0)