Skip to content

Commit ae6420b

Browse files
committed
Fixes #99.
Stable Version 0.10.2.
1 parent 9e34ce2 commit ae6420b

File tree

10 files changed

+68
-16
lines changed

10 files changed

+68
-16
lines changed

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
##### 0.10.2 - 21 July 2014
2+
3+
###### Backwards compatible bug fixes
4+
- #99 - Computed properties + uglify
5+
16
##### 0.10.1 - 20 July 2014
27

3-
##### Backwards compatible API changes
8+
###### Backwards compatible API changes
49
- #93 - Added `DS.createInstance(resourceName[, attrs][, options])`
510
- #96 - Resource definitions should be able to proxy DS methods
611

bower.json

+1-1
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.1",
5+
"version": "0.10.2",
66
"homepage": "http://angular-data.pseudobry.com/",
77
"repository": {
88
"type": "git",

dist/angular-data.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -4332,8 +4332,14 @@ function defineResource(definition) {
43324332
if (def.methods && field in def.methods) {
43334333
DS.$log.warn(errorPrefix + 'Computed property "' + field + '" conflicts with previously defined prototype method!');
43344334
}
4335-
var match = fn.toString().match(/function.*?\(([\s\S]*?)\)/);
4336-
var deps = match[1].split(',');
4335+
var deps;
4336+
if (angular.isFunction(fn)) {
4337+
var match = fn.toString().match(/function.*?\(([\s\S]*?)\)/);
4338+
deps = match[1].split(',');
4339+
DS.$log.warn(errorPrefix + 'Use the computed property array for compatibility with minified code!');
4340+
} else {
4341+
deps = fn.slice(0, fn.length - 1);
4342+
}
43374343
fn.deps = DS.utils.filter(deps, function (dep) {
43384344
return !!dep;
43394345
});
@@ -4992,7 +4998,11 @@ function _inject(definition, resource, attrs) {
49924998
args.push(item[dep]);
49934999
});
49945000
// recompute property
4995-
item[field] = fn.apply(item, args);
5001+
if (angular.isFunction(fn)) {
5002+
item[field] = fn.apply(item, args);
5003+
} else {
5004+
item[field] = fn[fn.length - 1].apply(item, args);
5005+
}
49965006
}
49975007
});
49985008
}

dist/angular-data.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

guide/angular-data/resource/resource.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,14 @@ DS.defineResource('user', {
419419
computed: {
420420
// each function's argument list defines the fields
421421
// that the computed property depends on
422-
fullName: function (first, last) {
422+
fullName: ['first', 'last', function (first, last) {
423423
return first + ' ' + last;
424+
}],
425+
// shortand, use the array syntax above if you want
426+
// you computed properties to work after you've
427+
// minified your code
428+
initials: function (first, last) {
429+
return first.toUppercase()[0] + '. ' + last.toUppercase()[0] + '.';
424430
}
425431
}
426432
});
@@ -439,7 +445,7 @@ user.first = 'Fred';
439445
// computed property hasn't been updated yet
440446
user.fullName; // "John Anderson"
441447

442-
DS.digest();
448+
DS.digest(); // or $scope.$apply()
443449

444450
user.fullName; // "Fred Anderson"
445451

guide/nav.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<i class="icon-wrench icon-white"></i> API <b class="caret"></b>
7373
</a>
7474
<ul class="dropdown-menu">
75-
<li class="nav-header">Angular-data - 0.10.1</li>
75+
<li class="nav-header">Angular-data - 0.10.2</li>
7676
<li>
7777
<a href="/documentation/api/angular-data/angular-data">Overview</a>
7878
</li>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-data",
33
"description": "Data store for Angular.js.",
4-
"version": "0.10.1",
4+
"version": "0.10.2",
55
"homepage": "http://angular-data.pseudobry.com",
66
"repository": {
77
"type": "git",

src/datastore/sync_methods/defineResource.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,14 @@ function defineResource(definition) {
164164
if (def.methods && field in def.methods) {
165165
DS.$log.warn(errorPrefix + 'Computed property "' + field + '" conflicts with previously defined prototype method!');
166166
}
167-
var match = fn.toString().match(/function.*?\(([\s\S]*?)\)/);
168-
var deps = match[1].split(',');
167+
var deps;
168+
if (angular.isFunction(fn)) {
169+
var match = fn.toString().match(/function.*?\(([\s\S]*?)\)/);
170+
deps = match[1].split(',');
171+
DS.$log.warn(errorPrefix + 'Use the computed property array for compatibility with minified code!');
172+
} else {
173+
deps = fn.slice(0, fn.length - 1);
174+
}
169175
fn.deps = DS.utils.filter(deps, function (dep) {
170176
return !!dep;
171177
});

src/datastore/sync_methods/inject.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ function _inject(definition, resource, attrs) {
2828
args.push(item[dep]);
2929
});
3030
// recompute property
31-
item[field] = fn.apply(item, args);
31+
if (angular.isFunction(fn)) {
32+
item[field] = fn.apply(item, args);
33+
} else {
34+
item[field] = fn[fn.length - 1].apply(item, args);
35+
}
3236
}
3337
});
3438
}

test/integration/datastore/sync_methods/defineResource.test.js

+24-3
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,31 @@ describe('DS.defineResource(definition)', function () {
160160
}
161161
});
162162

163+
DS.defineResource({
164+
name: 'dog',
165+
computed: {
166+
fullName: ['first', 'last', function (f, l) {
167+
callCount++;
168+
return f + ' ' + l;
169+
}]
170+
}
171+
});
172+
163173
DS.inject('person', {
164174
first: 'John',
165175
last: 'Anderson',
166176
167177
id: 1
168178
});
169179

180+
DS.inject('dog', {
181+
first: 'doggy',
182+
last: 'dog',
183+
id: 1
184+
});
185+
170186
var person = DS.get('person', 1);
187+
var dog = DS.get('dog', 1);
171188

172189
assert.deepEqual(JSON.stringify(person), JSON.stringify({
173190
first: 'John',
@@ -177,14 +194,16 @@ describe('DS.defineResource(definition)', function () {
177194
fullName: 'John Anderson'
178195
}));
179196
assert.equal(person.fullName, 'John Anderson');
180-
assert.equal(lifecycle.beforeInject.callCount, 1, 'beforeInject should have been called');
181-
assert.equal(lifecycle.afterInject.callCount, 1, 'afterInject should have been called');
197+
assert.equal(dog.fullName, 'doggy dog');
198+
assert.equal(lifecycle.beforeInject.callCount, 2, 'beforeInject should have been called twice');
199+
assert.equal(lifecycle.afterInject.callCount, 2, 'afterInject should have been called twice');
182200

183201
person.first = 'Johnny';
184202

185203
// digest loop hasn't happened yet
186204
assert.equal(DS.get('person', 1).first, 'Johnny');
187205
assert.equal(DS.get('person', 1).fullName, 'John Anderson');
206+
assert.equal(DS.get('dog', 1).fullName, 'doggy dog');
188207

189208
DS.digest();
190209

@@ -199,6 +218,7 @@ describe('DS.defineResource(definition)', function () {
199218
assert.equal(person.fullName, 'Johnny Anderson');
200219

201220
person.first = 'Jack';
221+
dog.first = 'spot';
202222

203223
DS.digest();
204224

@@ -211,6 +231,7 @@ describe('DS.defineResource(definition)', function () {
211231
fullName: 'Jack Anderson'
212232
});
213233
assert.equal(person.fullName, 'Jack Anderson');
234+
assert.equal(dog.fullName, 'spot dog');
214235

215236
// computed property function should not be called
216237
// when a property changes that isn't a dependency
@@ -219,7 +240,7 @@ describe('DS.defineResource(definition)', function () {
219240

220241
DS.digest();
221242

222-
assert.equal(callCount, 3, 'fullName() should have been called 3 times');
243+
assert.equal(callCount, 5, 'fullName() should have been called 3 times');
223244

224245
done();
225246
}, 50);

0 commit comments

Comments
 (0)