Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit e4c62ea

Browse files
committed
Merge branch 'master' into kato-400
2 parents 99c36b1 + adfdd00 commit e4c62ea

15 files changed

+158
-57
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ before_script:
1818
- phantomjs --version
1919
script:
2020
- sh ./tests/travis.sh
21+
after_script:
22+
- cat ./tests/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
2123
env:
2224
global:
2325
- secure: mGHp1rQI11OvbBQn3PnBT5kuyo26gFl8U+nNq0Ot4opgSBX9JaHqS8Dx63uALWWU9qjy08/Mn68t/sKhayH1+XrPDIenOy/XEkkSAG60qAAowD9dRo3WaIMSOcWWYDeqdZOAWZ3LiXvjLO4Swagz5ejz7UtY/ws4CcTi2n/fp7c=

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# AngularFire
33

44
[![Build Status](https://travis-ci.org/firebase/angularfire.svg?branch=master)](https://travis-ci.org/firebase/angularfire)
5+
[![Coverage Status](https://img.shields.io/coveralls/firebase/angularfire.svg)](https://coveralls.io/r/firebase/angularfire)
56
[![Version](https://badge.fury.io/gh/firebase%2Fangularfire.svg)](http://badge.fury.io/gh/firebase%2Fangularfire)
67

78
AngularFire is the officially supported [AngularJS](http://angularjs.org/) binding for

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"firebase": "1.0.x"
3535
},
3636
"devDependencies": {
37+
"coveralls": "^2.11.1",
3738
"grunt": "~0.4.1",
3839
"grunt-cli": "^0.1.13",
3940
"grunt-contrib-concat": "^0.4.0",
@@ -45,16 +46,16 @@
4546
"grunt-notify": "~0.2.7",
4647
"grunt-protractor-runner": "^1.0.0",
4748
"grunt-shell-spawn": "^0.3.0",
49+
"jasmine-spec-reporter": "^0.4.0",
4850
"karma": "~0.12.0",
51+
"karma-chrome-launcher": "^0.1.4",
52+
"karma-coverage": "^0.2.4",
53+
"karma-failed-reporter": "0.0.2",
4954
"karma-jasmine": "~0.2.0",
5055
"karma-phantomjs-launcher": "~0.1.0",
5156
"karma-sauce-launcher": "~0.2.9",
52-
"load-grunt-tasks": "~0.2.0",
53-
"protractor": "^1.0.0",
54-
"karma-coverage": "^0.2.4",
55-
"karma-failed-reporter": "0.0.2",
56-
"jasmine-spec-reporter": "^0.4.0",
5757
"karma-spec-reporter": "0.0.13",
58-
"karma-chrome-launcher": "^0.1.4"
58+
"load-grunt-tasks": "~0.2.0",
59+
"protractor": "^1.0.0"
5960
}
6061
}

src/FirebaseArray.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@
265265
}
266266
rec.$id = snap.name();
267267
rec.$priority = snap.getPriority();
268+
$firebaseUtils.applyDefaults(rec, this.$$defaults);
268269

269270
// add it to array and send notifications
270271
this._process('child_added', rec, prevChild);
@@ -295,6 +296,7 @@
295296
if( angular.isObject(rec) ) {
296297
// apply changes to the record
297298
var changed = $firebaseUtils.updateRec(rec, snap);
299+
$firebaseUtils.applyDefaults(rec, this.$$defaults);
298300
if( changed ) {
299301
this._process('child_changed', rec);
300302
}

src/FirebaseObject.js

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,26 @@
3838
* @constructor
3939
*/
4040
function FirebaseObject($firebase, destroyFn, readyPromise) {
41-
var self = this;
42-
43-
// These are private config props and functions used internally
44-
// they are collected here to reduce clutter on the prototype
45-
// and instance signatures.
46-
self.$$conf = {
41+
// IDE does not understand defineProperty so declare traditionally
42+
// to avoid lots of IDE warnings about invalid properties
43+
this.$$conf = {
4744
promise: readyPromise,
4845
inst: $firebase,
4946
bound: null,
5047
destroyFn: destroyFn,
51-
listeners: [],
52-
/**
53-
* Updates any bound scope variables and notifies listeners registered
54-
* with $watch any time there is a change to data
55-
*/
56-
notify: function() {
57-
if( self.$$conf.bound ) {
58-
self.$$conf.bound.update();
59-
}
60-
// be sure to do this after setting up data and init state
61-
angular.forEach(self.$$conf.listeners, function (parts) {
62-
parts[0].call(parts[1], {event: 'value', key: self.$id});
63-
});
64-
}
48+
listeners: []
6549
};
6650

67-
self.$id = $firebase.$ref().ref().name();
68-
self.$priority = null;
51+
// this bit of magic makes $$conf non-enumerable and non-configurable
52+
// and non-writable (its properties are still writable but the ref cannot be replaced)
53+
Object.defineProperty(this, '$$conf', {
54+
value: this.$$conf
55+
});
56+
57+
this.$id = $firebase.$ref().ref().name();
58+
this.$priority = null;
59+
60+
$firebaseUtils.applyDefaults(this, this.$$defaults);
6961
}
7062

7163
FirebaseObject.prototype = {
@@ -74,7 +66,7 @@
7466
* @returns a promise which will resolve after the save is completed.
7567
*/
7668
$save: function () {
77-
var notify = this.$$conf.notify;
69+
var notify = this.$$notify.bind(this);
7870
return this.$inst().$set($firebaseUtils.toJSON(this))
7971
.then(function(ref) {
8072
notify();
@@ -222,10 +214,11 @@
222214
$$updated: function (snap) {
223215
// applies new data to this object
224216
var changed = $firebaseUtils.updateRec(this, snap);
217+
$firebaseUtils.applyDefaults(this, this.$$defaults);
225218
if( changed ) {
226219
// notifies $watch listeners and
227220
// updates $scope if bound to a variable
228-
this.$$conf.notify();
221+
this.$$notify();
229222
}
230223
},
231224

@@ -239,6 +232,30 @@
239232
$log.error(err);
240233
// frees memory and cancels any remaining listeners
241234
this.$destroy(err);
235+
},
236+
237+
/**
238+
* Updates any bound scope variables and notifies listeners registered
239+
* with $watch any time there is a change to data
240+
*/
241+
$$notify: function() {
242+
var self = this;
243+
if( self.$$conf.bound ) {
244+
self.$$conf.bound.update();
245+
}
246+
// be sure to do this after setting up data and init state
247+
angular.forEach(self.$$conf.listeners, function (parts) {
248+
parts[0].call(parts[1], {event: 'value', key: self.$id});
249+
});
250+
},
251+
252+
/**
253+
* Overrides how Angular.forEach iterates records on this object so that only
254+
* fields stored in Firebase are part of the iteration. To include meta fields like
255+
* $id and $priority in the iteration, utilize for(key in obj) instead.
256+
*/
257+
forEach: function(iterator, context) {
258+
return $firebaseUtils.each(this, iterator, context);
242259
}
243260
};
244261

src/firebase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
throw new Error('config.arrayFactory must be a valid function');
171171
}
172172
if (!angular.isFunction(cnf.objectFactory)) {
173-
throw new Error('config.arrayFactory must be a valid function');
173+
throw new Error('config.objectFactory must be a valid function');
174174
}
175175
}
176176
};

src/firebaseSimpleLogin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* istanbul ignore next */
12
(function() {
23
'use strict';
34
var AngularFireAuth;
File renamed without changes.

src/utils.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,20 @@
224224
angular.extend(rec, data);
225225
rec.$priority = snap.getPriority();
226226

227-
if( angular.isObject(rec.$$defaults) ) {
228-
angular.forEach(rec.$$defaults, function(v,k) {
227+
return !angular.equals(oldData, rec) ||
228+
oldData.$value !== rec.$value ||
229+
oldData.$priority !== rec.$priority;
230+
},
231+
232+
applyDefaults: function(rec, defaults) {
233+
if( angular.isObject(defaults) ) {
234+
angular.forEach(defaults, function(v,k) {
229235
if( !rec.hasOwnProperty(k) ) {
230236
rec[k] = v;
231237
}
232238
});
233239
}
234-
235-
return !angular.equals(oldData, rec) ||
236-
oldData.$value !== rec.$value ||
237-
oldData.$priority !== rec.$priority;
240+
return rec;
238241
},
239242

240243
dataKeys: function(obj) {
@@ -246,12 +249,22 @@
246249
},
247250

248251
each: function(obj, iterator, context) {
249-
angular.forEach(obj, function(v,k) {
250-
var c = k.charAt(0);
251-
if( c !== '_' && c !== '$' && c !== '.' ) {
252-
iterator.call(context, v, k, obj);
252+
if(angular.isObject(obj)) {
253+
for (var k in obj) {
254+
if (obj.hasOwnProperty(k)) {
255+
var c = k.charAt(0);
256+
if( c !== '_' && c !== '$' && c !== '.' ) {
257+
iterator.call(context, obj[k], k, obj);
258+
}
259+
}
253260
}
254-
});
261+
}
262+
else if(angular.isArray(obj)) {
263+
for(var i = 0, len = obj.length; i < len; i++) {
264+
iterator.call(context, obj[i], i, obj);
265+
}
266+
}
267+
return obj;
255268
},
256269

257270
/**

tests/automatic_karma.conf.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@ module.exports = function(config) {
1010
singleRun: true,
1111

1212
preprocessors: {
13-
"../src/**/*.js": "coverage"
13+
"../src/*.js": "coverage"
1414
},
15+
1516
coverageReporter: {
16-
type: "html"
17+
reporters: [
18+
{
19+
type: "lcovonly",
20+
dir: "coverage",
21+
subdir: "."
22+
},
23+
{
24+
type: "text-summary"
25+
}
26+
]
1727
},
1828

1929
files: [

0 commit comments

Comments
 (0)