Skip to content

Commit

Permalink
Stable Version 1.0.0-alpha.4-2.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed Nov 10, 2014
1 parent 892bd90 commit fa95ba6
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 41 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,11 @@
##### 1.0.0-alpha.4-2 - 09 November 2014

###### Backwards compatible API changes
- jmdobry/angular-data#227 - Supporting methods on model instances

###### Backwards compatible bug fixes
- jmdobry/angular-data#235 - IE 8 support

##### 1.0.0-alpha.4-1 - 08 November 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.4-1](https://github.com/js-data/js-data/releases/tag/1.0.0-alpha.4-1)
__Latest Release:__ [1.0.0-alpha.4-2](https://github.com/js-data/js-data/releases/tag/1.0.0-alpha.4-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.4-1",
"version": "1.0.0-alpha.4-2",
"homepage": "http://www.js-data.io",
"repository": {
"type": "git",
Expand Down
56 changes: 38 additions & 18 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.4-1 - Homepage <http://www.js-data.io/>
* @version 1.0.0-alpha.4-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 All @@ -26,6 +26,7 @@
// Copyright 2014 Jason Dobry
//
// Summary of modifications:
// Fixed use of "delete" keyword for IE8 compatibility
// Removed all code related to:
// - ArrayObserver
// - ArraySplice
Expand Down Expand Up @@ -523,7 +524,7 @@
var expectedRecordTypes = {
add: true,
update: true,
delete: true
'delete': true
};

function diffObjectFromChangeRecords(object, changeRecords, oldValues) {
Expand Down Expand Up @@ -2849,7 +2850,7 @@ function destroy(resourceName, id, options) {
}
_this.eject(resourceName, id);
return id;
}).catch(function (err) {
})['catch'](function (err) {
if (options.eagerEject && item) {
_this.inject(resourceName, item, { notify: false });
}
Expand All @@ -2868,9 +2869,13 @@ function destroyAll(resourceName, params, options) {
var definition = _this.definitions[resourceName];
var ejected, toEject;

params = params || {};

return new DSUtils.Promise(function (resolve, reject) {
if (!definition) {
reject(new DSErrors.NER(resourceName));
} else if (!DSUtils.isObject(params)) {
reject(new DSErrors.IA('"params" must be an object!'));
} else {
options = DSUtils._(definition, options);
resolve();
Expand All @@ -2893,7 +2898,7 @@ function destroyAll(resourceName, params, options) {
_this.emit(definition, 'afterDestroy', toEject);
}
return ejected || _this.ejectAll(resourceName, params);
}).catch(function (err) {
})['catch'](function (err) {
if (options.eagerEject && ejected) {
_this.inject(resourceName, ejected, { notify: false });
}
Expand Down Expand Up @@ -2947,7 +2952,7 @@ function find(resourceName, id, options) {
} else {
return item;
}
}).catch(function (err) {
})['catch'](function (err) {
delete resource.pendingQueries[id];
throw err;
});
Expand Down Expand Up @@ -3039,7 +3044,7 @@ function findAll(resourceName, params, options) {
} else {
return items;
}
}).catch(function (err) {
})['catch'](function (err) {
delete resource.pendingQueries[queryHash];
throw err;
});
Expand Down Expand Up @@ -3734,7 +3739,18 @@ var instanceMethods = [
'compute',
'refresh',
'save',
'update'
'update',
'destroy',
'loadRelations',
'changeHistory',
'changes',
'hasChanges',
'lastModified',
'lastSaved',
'link',
'linkInverse',
'previous',
'unlinkInverse'
];

function defineResource(definition) {
Expand Down Expand Up @@ -3837,13 +3853,13 @@ function defineResource(definition) {
}

// Create the wrapper class for the new resource
def.class = DSUtils.pascalCase(definition.name);
eval('function ' + def.class + '() {}');
def[def.class] = eval(def.class);
def['class'] = DSUtils.pascalCase(definition.name);
eval('function ' + def['class'] + '() {}');
def[def['class']] = eval(def['class']);

// Apply developer-defined methods
if (def.methods) {
DSUtils.deepMixIn(def[def.class].prototype, def.methods);
DSUtils.deepMixIn(def[def['class']].prototype, def.methods);
}

// Prepare for computed properties
Expand Down Expand Up @@ -3893,9 +3909,9 @@ function defineResource(definition) {
}

DSUtils.forEach(instanceMethods, function (name) {
def[def.class].prototype['DS' + DSUtils.pascalCase(name)] = function () {
def[def['class']].prototype['DS' + DSUtils.pascalCase(name)] = function () {
var args = Array.prototype.slice.call(arguments);
args.unshift(this);
args.unshift(this[def.idAttribute] || this);
args.unshift(def.name);
return _this[name].apply(_this, args);
};
Expand Down Expand Up @@ -4278,9 +4294,13 @@ function getAll(resourceName, ids) {

function hasChanges(resourceName, id) {
var _this = this;

id = DSUtils.resolveId(_this.definitions[resourceName], id);

if (!_this.definitions[resourceName]) {
throw new NER(resourceName);
} else if (!DSUtils.isString(id) && !DSUtils.isNumber(id)) {
throw new IA('"id" must be a string or a number!');
}

// return resource from cache
Expand Down Expand Up @@ -4481,10 +4501,10 @@ function _inject(definition, resource, attrs, options) {

if (!item) {
if (options.useClass) {
if (attrs instanceof definition[definition.class]) {
if (attrs instanceof definition[definition['class']]) {
item = attrs;
} else {
item = new definition[definition.class]();
item = new definition[definition['class']]();
}
} else {
item = {};
Expand Down Expand Up @@ -4808,7 +4828,7 @@ function IllegalArgumentError(message) {
this.message = message || 'Illegal Argument!';
}

IllegalArgumentError.prototype = Object.create(Error.prototype);
IllegalArgumentError.prototype = new Error();
IllegalArgumentError.prototype.constructor = IllegalArgumentError;

function RuntimeError(message) {
Expand All @@ -4820,7 +4840,7 @@ function RuntimeError(message) {
this.message = message || 'RuntimeError Error!';
}

RuntimeError.prototype = Object.create(Error.prototype);
RuntimeError.prototype = new Error();
RuntimeError.prototype.constructor = RuntimeError;

function NonexistentResourceError(resourceName) {
Expand All @@ -4832,7 +4852,7 @@ function NonexistentResourceError(resourceName) {
this.message = (resourceName || '') + ' is not a registered resource!';
}

NonexistentResourceError.prototype = Object.create(Error.prototype);
NonexistentResourceError.prototype = new Error();
NonexistentResourceError.prototype.constructor = NonexistentResourceError;

module.exports = {
Expand Down
6 changes: 3 additions & 3 deletions dist/js-data.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion lib/observe-js/observe-js.js
Expand Up @@ -16,6 +16,7 @@
// Copyright 2014 Jason Dobry
//
// Summary of modifications:
// Fixed use of "delete" keyword for IE8 compatibility
// Removed all code related to:
// - ArrayObserver
// - ArraySplice
Expand Down Expand Up @@ -513,7 +514,7 @@
var expectedRecordTypes = {
add: true,
update: true,
delete: true
'delete': true
};

function diffObjectFromChangeRecords(object, changeRecords, oldValues) {
Expand Down
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.4-1",
"version": "1.0.0-alpha.4-2",
"homepage": "http://www.js-data.io",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/datastore/async_methods/destroy.js
Expand Up @@ -41,7 +41,7 @@ function destroy(resourceName, id, options) {
}
_this.eject(resourceName, id);
return id;
}).catch(function (err) {
})['catch'](function (err) {
if (options.eagerEject && item) {
_this.inject(resourceName, item, { notify: false });
}
Expand Down
2 changes: 1 addition & 1 deletion src/datastore/async_methods/destroyAll.js
Expand Up @@ -35,7 +35,7 @@ function destroyAll(resourceName, params, options) {
_this.emit(definition, 'afterDestroy', toEject);
}
return ejected || _this.ejectAll(resourceName, params);
}).catch(function (err) {
})['catch'](function (err) {
if (options.eagerEject && ejected) {
_this.inject(resourceName, ejected, { notify: false });
}
Expand Down
2 changes: 1 addition & 1 deletion src/datastore/async_methods/find.js
Expand Up @@ -41,7 +41,7 @@ function find(resourceName, id, options) {
} else {
return item;
}
}).catch(function (err) {
})['catch'](function (err) {
delete resource.pendingQueries[id];
throw err;
});
Expand Down
2 changes: 1 addition & 1 deletion src/datastore/async_methods/findAll.js
Expand Up @@ -81,7 +81,7 @@ function findAll(resourceName, params, options) {
} else {
return items;
}
}).catch(function (err) {
})['catch'](function (err) {
delete resource.pendingQueries[queryHash];
throw err;
});
Expand Down
25 changes: 18 additions & 7 deletions src/datastore/sync_methods/defineResource.js
Expand Up @@ -17,7 +17,18 @@ var instanceMethods = [
'compute',
'refresh',
'save',
'update'
'update',
'destroy',
'loadRelations',
'changeHistory',
'changes',
'hasChanges',
'lastModified',
'lastSaved',
'link',
'linkInverse',
'previous',
'unlinkInverse'
];

function defineResource(definition) {
Expand Down Expand Up @@ -120,13 +131,13 @@ function defineResource(definition) {
}

// Create the wrapper class for the new resource
def.class = DSUtils.pascalCase(definition.name);
eval('function ' + def.class + '() {}');
def[def.class] = eval(def.class);
def['class'] = DSUtils.pascalCase(definition.name);
eval('function ' + def['class'] + '() {}');
def[def['class']] = eval(def['class']);

// Apply developer-defined methods
if (def.methods) {
DSUtils.deepMixIn(def[def.class].prototype, def.methods);
DSUtils.deepMixIn(def[def['class']].prototype, def.methods);
}

// Prepare for computed properties
Expand Down Expand Up @@ -176,9 +187,9 @@ function defineResource(definition) {
}

DSUtils.forEach(instanceMethods, function (name) {
def[def.class].prototype['DS' + DSUtils.pascalCase(name)] = function () {
def[def['class']].prototype['DS' + DSUtils.pascalCase(name)] = function () {
var args = Array.prototype.slice.call(arguments);
args.unshift(this);
args.unshift(this[def.idAttribute] || this);
args.unshift(def.name);
return _this[name].apply(_this, args);
};
Expand Down
4 changes: 4 additions & 0 deletions src/datastore/sync_methods/index.js
Expand Up @@ -178,9 +178,13 @@ function getAll(resourceName, ids) {

function hasChanges(resourceName, id) {
var _this = this;

id = DSUtils.resolveId(_this.definitions[resourceName], id);

if (!_this.definitions[resourceName]) {
throw new NER(resourceName);
} else if (!DSUtils.isString(id) && !DSUtils.isNumber(id)) {
throw new IA('"id" must be a string or a number!');
}

// return resource from cache
Expand Down
4 changes: 2 additions & 2 deletions src/datastore/sync_methods/inject.js
Expand Up @@ -117,10 +117,10 @@ function _inject(definition, resource, attrs, options) {

if (!item) {
if (options.useClass) {
if (attrs instanceof definition[definition.class]) {
if (attrs instanceof definition[definition['class']]) {
item = attrs;
} else {
item = new definition[definition.class]();
item = new definition[definition['class']]();
}
} else {
item = {};
Expand Down
6 changes: 3 additions & 3 deletions src/errors.js
Expand Up @@ -7,7 +7,7 @@ function IllegalArgumentError(message) {
this.message = message || 'Illegal Argument!';
}

IllegalArgumentError.prototype = Object.create(Error.prototype);
IllegalArgumentError.prototype = new Error();
IllegalArgumentError.prototype.constructor = IllegalArgumentError;

function RuntimeError(message) {
Expand All @@ -19,7 +19,7 @@ function RuntimeError(message) {
this.message = message || 'RuntimeError Error!';
}

RuntimeError.prototype = Object.create(Error.prototype);
RuntimeError.prototype = new Error();
RuntimeError.prototype.constructor = RuntimeError;

function NonexistentResourceError(resourceName) {
Expand All @@ -31,7 +31,7 @@ function NonexistentResourceError(resourceName) {
this.message = (resourceName || '') + ' is not a registered resource!';
}

NonexistentResourceError.prototype = Object.create(Error.prototype);
NonexistentResourceError.prototype = new Error();
NonexistentResourceError.prototype.constructor = NonexistentResourceError;

module.exports = {
Expand Down

0 comments on commit fa95ba6

Please sign in to comment.