Skip to content

Commit

Permalink
Closes #20.
Browse files Browse the repository at this point in the history
Stable Version 1.0.0-alpha.2.
  • Loading branch information
jmdobry committed Oct 31, 2014
1 parent 8435e02 commit 1136081
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
##### 1.0.0-alpha.2 - 31 October 2014

###### Backwards compatible API changes
- #20 - es6-promise finally polyfill

##### 1.0.0-alpha.1-2 - 30 October 2014

###### Backwards compatible bug fixes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -10,7 +10,7 @@ Unlike Backbone and Ember Models, js-data does not require the use of getters an

Supporting relations, computed properties, model lifecycle control and a slew of other features, js-data is the tool for giving your data the respect it deserves.

__Latest Release:__ [1.0.0-alpha.1-1](https://github.com/js-data/js-data/releases/tag/1.0.0-alpha.1-1)
__Latest Release:__ [1.0.0-alpha.2](https://github.com/js-data/js-data/releases/tag/1.0.0-alpha.2)

js-data is pre-release. The API is subject to change, though the current api is well tested.

Expand Down
2 changes: 1 addition & 1 deletion bower.json
@@ -1,7 +1,7 @@
{
"name": "js-data",
"description": "Robust, framework-agnostic in-memory data store.",
"version": "1.0.0-alpha.1-2",
"version": "1.0.0-alpha.2",
"homepage": "http://www.js-data.io",
"repository": {
"type": "git",
Expand Down
32 changes: 30 additions & 2 deletions dist/js-data.js
@@ -1,7 +1,7 @@
/**
* @author Jason Dobry <jason.dobry@gmail.com>
* @file js-data.js
* @version 1.0.0-alpha.1-2 - Homepage <http://www.js-data.io/>
* @version 1.0.0-alpha.2 - Homepage <http://www.js-data.io/>
* @copyright (c) 2014 Jason Dobry
* @license MIT <https://github.com/js-data/js-data/blob/master/LICENSE>
*
Expand Down Expand Up @@ -4829,15 +4829,42 @@ module.exports = {
};

},{"./datastore":56,"./errors":67,"./utils":69}],69:[function(require,module,exports){
(function (global){
var DSErrors = require('./errors');
var isFunction = require('mout/lang/isFunction');
var w;
var _Promise;

var es6Promise = require('es6-promise');
es6Promise.polyfill();

function finallyPolyfill(cb) {
var constructor = this.constructor;

return this.then(function (value) {
return constructor.resolve(cb()).then(function () {
return value;
});
}, function (reason) {
return constructor.resolve(cb()).then(function () {
throw reason;
});
});
}

try {
w = window;
if (!w.Promise.prototype['finally']) {
w.Promise.prototype['finally'] = finallyPolyfill;
}
_Promise = w.Promise;
w = {};
} catch (e) {
w = null;
if (!global.Promise.prototype['finally']) {
global.Promise.prototype['finally'] = finallyPolyfill;
}
_Promise = global.Promise;
}

function updateTimestamp(timestamp) {
Expand Down Expand Up @@ -5091,7 +5118,7 @@ module.exports = {
}
},
updateTimestamp: updateTimestamp,
Promise: require('es6-promise').Promise,
Promise: _Promise,
deepFreeze: function deepFreeze(o) {
if (typeof Object.freeze === 'function' && typeof Object.isFrozen === 'function') {
var prop, propKey;
Expand Down Expand Up @@ -5184,5 +5211,6 @@ module.exports = {
Events: Events
};

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./errors":67,"es6-promise":2,"mout/array/contains":4,"mout/array/filter":5,"mout/array/forEach":6,"mout/array/remove":9,"mout/array/slice":10,"mout/array/sort":11,"mout/array/toLookup":12,"mout/lang/isArray":18,"mout/lang/isBoolean":19,"mout/lang/isEmpty":20,"mout/lang/isFunction":21,"mout/lang/isNumber":23,"mout/lang/isObject":24,"mout/lang/isString":26,"mout/object/deepMixIn":30,"mout/object/forOwn":32,"mout/object/merge":34,"mout/object/mixIn":35,"mout/object/pick":37,"mout/object/set":38,"mout/string/makePath":41,"mout/string/pascalCase":42,"mout/string/upperCase":45}]},{},[68])(68)
});
4 changes: 2 additions & 2 deletions dist/js-data.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "js-data",
"description": "Robust, framework-agnostic in-memory data store.",
"version": "1.0.0-alpha.1-2",
"version": "1.0.0-alpha.2",
"homepage": "http://www.js-data.io",
"repository": {
"type": "git",
Expand Down
28 changes: 27 additions & 1 deletion src/utils.js
@@ -1,12 +1,38 @@
var DSErrors = require('./errors');
var isFunction = require('mout/lang/isFunction');
var w;
var _Promise;

var es6Promise = require('es6-promise');
es6Promise.polyfill();

function finallyPolyfill(cb) {
var constructor = this.constructor;

return this.then(function (value) {
return constructor.resolve(cb()).then(function () {
return value;
});
}, function (reason) {
return constructor.resolve(cb()).then(function () {
throw reason;
});
});
}

try {
w = window;
if (!w.Promise.prototype['finally']) {
w.Promise.prototype['finally'] = finallyPolyfill;
}
_Promise = w.Promise;
w = {};
} catch (e) {
w = null;
if (!global.Promise.prototype['finally']) {
global.Promise.prototype['finally'] = finallyPolyfill;
}
_Promise = global.Promise;
}

function updateTimestamp(timestamp) {
Expand Down Expand Up @@ -260,7 +286,7 @@ module.exports = {
}
},
updateTimestamp: updateTimestamp,
Promise: require('es6-promise').Promise,
Promise: _Promise,
deepFreeze: function deepFreeze(o) {
if (typeof Object.freeze === 'function' && typeof Object.isFrozen === 'function') {
var prop, propKey;
Expand Down
15 changes: 15 additions & 0 deletions test/both/datastore/utils.test.js
Expand Up @@ -110,5 +110,20 @@ describe('DSUtils', function () {
}
}, 30);
});

it('should support "finally"', function (done) {
var promise = new DSUtils.Promise(function (resolve) {
resolve('data');
});

promise.then(function (data) {
assert.equal(data, 'data');
return data + data;
}).finally(function () {
done();
}, function (err) {
done('Should not have rejected!', err);
});
});
});
});

0 comments on commit 1136081

Please sign in to comment.