Skip to content

Commit

Permalink
Stable Version 0.4.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed Oct 2, 2014
1 parent 6d219d5 commit 13aadcc
Show file tree
Hide file tree
Showing 72 changed files with 2,532 additions and 2,233 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
@@ -1,8 +1,14 @@
##### 0.4.1 - xx September 2014
##### 0.4.1 - 01 October 2014

###### Backwards compatible API changes
- #9 - Make all options passed to methods also inherit from Resource defaults

###### Backwards compatible bug fixes
- jmdobry/angular-data/#195 - throw an error when you try to inject a relation but the resource for it hasn't been defined

###### Other
- Added official support for NodeJS

##### 0.4.0 - 25 September 2014

###### Breaking API changes
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
@@ -1,6 +1,6 @@
# Contributing Guide

First, feel free to contact me with questions. [Mailing List](https://groups.google.com/forum/?fromgroups#!forum/js-data). [Issues](https://github.com/js-data/js-data/issues).
First, feel free to contact me with questions. [Mailing List](https://groups.io/org/groupsio/jsdata). [Issues](https://github.com/js-data/js-data/issues).

1. Contribute to the issue that is the reason you'll be developing in the first place
1. Fork js-data
Expand Down
131 changes: 24 additions & 107 deletions Gruntfile.js
Expand Up @@ -9,7 +9,10 @@ module.exports = function (grunt) {
'use strict';

require('jit-grunt')(grunt, {
coveralls: 'grunt-karma-coveralls'
coveralls: 'grunt-karma-coveralls',
instrument: 'grunt-istanbul',
storeCoverage: 'grunt-istanbul',
makeReport: 'grunt-istanbul'
});
require('time-grunt')(grunt);

Expand All @@ -30,6 +33,10 @@ module.exports = function (grunt) {
dist: {
files: ['src/**/*.js'],
tasks: ['build']
},
n: {
files: ['src/**/*.js', 'test/both/**/*.js', 'test/node/**/*.js'],
tasks: ['n']
}
},
uglify: {
Expand Down Expand Up @@ -74,128 +81,34 @@ module.exports = function (grunt) {
preprocessors: {}
},
min: {
browsers: ['Firefox', 'PhantomJS'],
browsers: ['Firefox'],
options: {
files: [
'dist/js-data.min.js',
'bower_components/js-data-http/dist/js-data-http.min.js',
'bower_components/js-data-localstorage/dist/js-data-localstorage.min.js',
'karma.start.js',
'test/**/*.js'
'test/both/**/*.js',
'test/browser/**/*.js'
]
}
},
ci: {
browsers: ['Firefox', 'PhantomJS']
browsers: ['Firefox']
}
},
coveralls: {
options: {
coverage_dir: 'coverage'
}
},
docular: {
groups: [
// {
// groupTitle: 'Guide',
// groupId: 'guide',
// groupIcon: 'icon-book',
// sections: [
// {
// id: 'angular-data',
// title: 'angular-data',
// docs: [
// 'guide/angular-data/index.md',
// 'guide/angular-data/overview.md',
// 'guide/angular-data/resources.md',
// 'guide/angular-data/asynchronous.md',
// 'guide/angular-data/synchronous.md',
// 'guide/angular-data/queries.md',
// 'guide/angular-data/adapters.md',
// 'guide/angular-data/how.md'
// ],
// rank: {
// index: 1,
// overview: 2,
// resources: 3,
// asynchronous: 4,
// synchronous: 5,
// queries: 6,
// adapters: 7,
// how: 8
// }
// },
// {
// id: 'angular-cache',
// title: 'angular-cache',
// docs: ['guide/angular-cache/'],
// rank: {
// index: 1,
// basics: 2,
// configure: 3,
// http: 4,
// storage: 5
// }
// },
// {
// id: 'angular-data-mocks',
// title: 'angular-data-mocks',
// docs: ['guide/angular-data-mocks/'],
// rank: {
// index: 1,
// overview: 2,
// setup: 3,
// testing: 4
// }
// },
// {
// id: 'angular-data-resource',
// title: 'Defining Resources',
// docs: ['guide/angular-data/resource/'],
// rank: {
// index: 1,
// overview: 2,
// basic: 3,
// advanced: 4,
// lifecycle: 5,
// custom: 6,
// relations: 7
// }
// }
// ]
// },
{
groupTitle: 'API',
groupId: 'api',
groupIcon: 'icon-wrench',
showSource: true,
sections: [
{
id: 'js-data',
title: 'js-data',
scripts: [
'src/'
],
docs: ['guide/api']
}
]
}
],
docular_webapp_target: 'doc',
showDocularDocs: false,
showAngularDocs: false//,
// docular_partial_home: 'guide/home.html',
// docular_partial_navigation: 'guide/nav.html',
// docular_partial_footer: 'guide/footer.html',
// analytics: {
// account: 'UA-34445126-2',
// domainName: 'angular-data.pseudobry.com'
// },
// discussions: {
// shortName: 'angulardata',
// url: 'http://angular-data.pseudobry.com',
// dev: dev
// }
mochaTest: {
all: {
options: {
reporter: 'spec'
},
src: ['mocha.start.js', 'test/both/**/*.js', 'test/node/**/*.js']
}
}
});

Expand Down Expand Up @@ -225,7 +138,11 @@ module.exports = function (grunt) {
grunt.file.write('dist/js-data.js', file);
});

grunt.registerTask('test', ['build', 'karma:ci', 'karma:min']);
grunt.registerTask('n', ['mochaTest']);
grunt.registerTask('b', ['karma:ci', 'karma:min']);
grunt.registerTask('w', ['n', 'watch:n']);

grunt.registerTask('test', ['build', 'n', 'b']);
grunt.registerTask('build', [
'clean',
'jshint',
Expand Down
49 changes: 29 additions & 20 deletions README.md
Expand Up @@ -10,27 +10,31 @@ 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:__ [0.4.0](https://github.com/js-data/js-data/releases/tag/0.4.0)
__Latest Release:__ [0.4.1](https://github.com/js-data/js-data/releases/tag/0.4.1)

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

If you want to use js-data, keep a close eye on the changelog. 1.0.0 will introduce strict semver (until then, minor number is bumped for breaking changes).

## Supported Platforms

Browsers: Chrome, Firefox, IE 8+, Safari, Opera, iOS Safari 7.1+, Android Browser 2.3+

Node: 0.10+ (at least)

## Quick Start
`bower install --save js-data js-data-http` or `npm install --save js-data js-data-http`.

Load `js-data-http.js` after `js-data.js`.

```js
var dataStore = new JSData.DS();
var store = new JSData.DS();

dataStore.adapters.DSHttpAdapter = new DSHttpAdapter();

// use http by default for async operations
dataStore.defaults.defaultAdapter = 'DSHttpAdapter';
// register and use http by default for async operations
store.registerAdapter('http', new DSHttpAdapter(), { default: true });

// simplest model definition
var User = dataStore.defineResource('user');
var User = store.defineResource('user');

User.find(1).then(function (user) {
user; // { id: 1, name: 'John' }
Expand Down Expand Up @@ -67,27 +71,32 @@ First, feel free to contact me with questions. [Mailing List](https://groups.io/
1. `git clone https://github.com/<you>/js-data.git`
1. `cd js-data; npm install; bower install;`
1. `grunt go` (builds and starts a watch)
1. (in another terminal) `grunt karma:dev` (runs the tests)
1. (in another terminal) `grunt karma:dev` (runs the Karma tests)
1. (in another terminal) `grunt w` (runs the NodeJS tests)
1. Write your code, including relevant documentation and tests
1. Submit a PR and we'll review

## License

Copyright (C) 2014 Jason Dobry
The MIT License (MIT)

Copyright (c) 2014 Jason Dobry

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

41 changes: 31 additions & 10 deletions dist/js-data.js
Expand Up @@ -591,7 +591,7 @@
global.Observer.hasObjectObserve = hasObserve;

global.ObjectObserver = ObjectObserver;
})((exports.Number = { isNaN: window.isNaN }) ? exports : exports);
})(exports);

},{}],2:[function(require,module,exports){
"use strict";
Expand Down Expand Up @@ -3520,7 +3520,9 @@ function eject(resourceName, id, options) {
}
_this.unlinkInverse(definition.name, id);
resource.collection.splice(i, 1);
resource.observers[id].close();
if (resource.observers[id]) {
resource.observers[id].close();
}
delete resource.observers[id];

delete resource.index[id];
Expand Down Expand Up @@ -3634,7 +3636,9 @@ function changes(resourceName, id) {

var item = _this.get(resourceName, id);
if (item) {
_this.store[resourceName].observers[id].deliver();
if (DSUtils.w) {
_this.store[resourceName].observers[id].deliver();
}
var diff = DSUtils.diffObjectFromOldObject(item, _this.store[resourceName].previousAttributes[id]);
DSUtils.forOwn(diff, function (changeset, name) {
var toKeep = [];
Expand Down Expand Up @@ -3852,7 +3856,10 @@ function _injectRelations(definition, injected, options) {
DSUtils.forEach(definition.relationList, function (def) {
var relationName = def.relation;
var relationDef = _this.definitions[relationName];
if (relationDef && injected[def.localField]) {
if (injected[def.localField]) {
if (!relationDef) {
throw new DSErrors.R(definition.name + ' relation is defined, but the resource is not!');
}
try {
injected[def.localField] = _this.inject(relationName, injected[def.localField], options);
} catch (err) {
Expand Down Expand Up @@ -3974,10 +3981,13 @@ function _inject(definition, resource, attrs, options) {
resource.collection.push(item);

resource.changeHistories[id] = [];
resource.observers[id] = new observe.ObjectObserver(item);
resource.observers[id].open(_react, item);
resource.index[id] = item;

if (DSUtils.w) {
resource.observers[id] = new observe.ObjectObserver(item);
resource.observers[id].open(_react, item);
}

resource.index[id] = item;
_react.call(item, {}, {}, {}, null, true);

if (definition.relations) {
Expand All @@ -3995,12 +4005,14 @@ function _inject(definition, resource, attrs, options) {
resource.changeHistories[id].splice(0, resource.changeHistories[id].length);
}
}
resource.observers[id].deliver();
if (DSUtils.w) {
resource.observers[id].deliver();
}
}
resource.saved[id] = DSUtils.updateTimestamp(resource.saved[id]);
injected = item;
} catch (err) {
console.error(err);
console.error(err.stack);
console.error('inject failed!', definition.name, attrs);
}
}
Expand Down Expand Up @@ -4417,8 +4429,17 @@ function Events(target) {
}

var DSErrors = require('./errors');
var w;

try {
w = window;
w = {};
} catch (e) {
w = null;
}

module.exports = {
w: w,
isBoolean: require('mout/lang/isBoolean'),
isString: require('mout/lang/isString'),
isArray: require('mout/lang/isArray'),
Expand Down Expand Up @@ -4489,7 +4510,7 @@ module.exports = {
Object.freeze(o); // First freeze the object.
for (propKey in o) {
prop = o[propKey];
if (!o.hasOwnProperty(propKey) || typeof prop !== 'object' || Object.isFrozen(prop)) {
if (!prop || !o.hasOwnProperty(propKey) || typeof prop !== 'object' || Object.isFrozen(prop)) {
// If the object is on the prototype, not an object, or is already frozen,
// skip it. Note that this might leave an unfrozen reference somewhere in the
// object if there is an already frozen object containing an unfrozen object.
Expand Down
4 changes: 2 additions & 2 deletions dist/js-data.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion karma.conf.js
Expand Up @@ -24,7 +24,8 @@ module.exports = function (config) {
'bower_components/js-data-http/dist/js-data-http.js',
'bower_components/js-data-localstorage/dist/js-data-localstorage.js',
'karma.start.js',
'test/**/*.test.js'
'test/both/**/*.test.js',
'test/browser/**/*.test.js'
],

reporters: ['spec', 'coverage'],
Expand Down

0 comments on commit 13aadcc

Please sign in to comment.