Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

The wonderful "white" hint

  • Loading branch information...
commit f4a5da1c6d4c1de47dd6940b8670a6c84957a81d 1 parent a95c18f
@kriszyp kriszyp authored
View
42 Cache.js
@@ -5,7 +5,7 @@ define([
'dojo/_base/declare',
'./Store',
'./Memory'
-], function(lang, arrayUtil, when, declare, Store, Memory){
+], function (lang, arrayUtil, when, declare, Store, Memory) {
// module:
// dstore/Cache
@@ -13,28 +13,28 @@ define([
return declare(Store, {
cachingStore: null,
constructor: function (options) {
- for(var i in options){
+ for (var i in options) {
// mixin the options
this[i] = options[i];
}
- if(!this.cachingStore){
+ if (!this.cachingStore) {
this.cachingStore = new Memory();
}
this._collectionCache = {};
},
_tryCacheForResults: function (method, serialized, args) {
var cachingStore = this.cachingStore;
- if(this.allLoaded && this.hasOwnProperty('cachingStore')){
+ if (this.allLoaded && this.hasOwnProperty('cachingStore')) {
// if we have loaded everything, we can go to the caching store
// for quick client side querying
var subCachingStore = new Memory();
// wait for it to finish loading
var data = when(when(this.allLoaded, function () {
return cachingStore[method].apply(cachingStore, args);
- }), function(results){
+ }), function (results) {
// now process the results to populate sub caching store
var data = results.data;
- for(var i = 0; i < data.length; i++){
+ for (var i = 0; i < data.length; i++) {
subCachingStore.put(data[i]);
}
return data;
@@ -50,13 +50,13 @@ define([
if (cacheable) {
// we use a key to see if we already have a sub-collection
serialized = method + ':' + serialized;
- if(this._collectionCache[serialized]){
+ if (this._collectionCache[serialized]) {
return this._collectionCache[serialized];
}
}
// nothing in the cache, have to use the inherited method to perform the action
var results = this.inherited(args);
- if(cacheable){
+ if (cacheable) {
this._collectionCache[serialized] = results;
}
// give the results it's own collection cache and caching store
@@ -64,11 +64,11 @@ define([
if (results.data) {
var store = this;
- when(results.allLoaded = results.data, function(data){
+ when(results.allLoaded = results.data, function (data) {
results.cachingStore = new Memory({data: data});
- for(var i = 0, l = data.length; i < l; i++){
+ for (var i = 0, l = data.length; i < l; i++) {
var object = data[i];
- if(!store.isLoaded || store.isLoaded(object)){
+ if (!store.isLoaded || store.isLoaded(object)) {
cachingStore.put(object);
}
}
@@ -93,15 +93,15 @@ define([
var store = this;
if (this.allLoaded) {
// everything has been loaded, use the caching store
- return when(this.allLoaded, function(){
+ return when(this.allLoaded, function () {
return store.cachingStore.fetch();
});
}
/* jshint boss: true */
- return this.allLoaded = when(this.inherited(arguments), function(results){
- arrayUtil.forEach(results, function(object){
+ return this.allLoaded = when(this.inherited(arguments), function (results) {
+ arrayUtil.forEach(results, function (object) {
// store each object before calling the callback
- if(!store.isLoaded || store.isLoaded(object)){
+ if (!store.isLoaded || store.isLoaded(object)) {
cachingStore.put(object);
}
});
@@ -118,10 +118,10 @@ define([
var masterGet = this.getInherited(arguments);
var masterStore = this;
// if everything is being loaded, we always wait for that to finish
- return when(this.allLoaded, function(){
- return when(cachingStore.get(id), function(result){
- return result || when(masterGet.call(masterStore, id, directives), function(result){
- if(result){
+ return when(this.allLoaded, function () {
+ return when(cachingStore.get(id), function (result) {
+ return result || when(masterGet.call(masterStore, id, directives), function (result) {
+ if (result) {
cachingStore.put(result, {id: id});
}
return result;
@@ -131,7 +131,7 @@ define([
},
add: function (object, directives) {
var cachingStore = this.cachingStore;
- return when(this.inherited(arguments), function(result){
+ return when(this.inherited(arguments), function (result) {
// now put result in cache (note we don't do add, because add may have
// called put() and already added it)
cachingStore.put(object && typeof result === 'object' ? result : object, directives);
@@ -143,7 +143,7 @@ define([
// first remove from the cache, so it is empty until we get a response from the master store
var cachingStore = this.cachingStore;
cachingStore.remove((directives && directives.id) || this.getIdentity(object));
- return when(this.inherited(arguments), function(result){
+ return when(this.inherited(arguments), function (result) {
// now put result in cache
cachingStore.put(object && typeof result === 'object' ? result : object, directives);
// the result from the put should be dictated by the master store and be unaffected by the cachingStore
View
2  ComputedProperty.js
@@ -62,7 +62,7 @@ define([
this._parent.property(dependsOn[i]).observe(changeListener, true));
}
return {
- remove: function() {
+ remove: function () {
for (var i = 0; i < dependsOn.length; i++) {
handles[i].remove();
}
View
8 Csv.js
@@ -1,7 +1,7 @@
define([
'dojo/_base/lang',
'dojo/_base/declare'
-], function(lang, declare) {
+], function (lang, declare) {
// originally from https://github.com/kfranqueiro/dojo-smore/blob/master/Csv.js
var quoteRx = /^\s*"([\S\s]*)"\s*$/,
doubleQuoteRx = /""/g,
@@ -43,7 +43,7 @@ define([
// If true, leading/trailing space will be trimmed from any unquoted values.
trim: false,
- parse: function(str) {
+ parse: function (str) {
// summary:
// Populates the store based on a CSV-formatted string.
// str: String
@@ -131,12 +131,12 @@ define([
// The data is assembled; return
return data;
},
- toCsv: function(options){
+ toCsv: function (options) {
// summary:
// Returns data from Memory store, re-exported to CSV format.
return this.stringify(this.data, options);
},
- stringify: function(data, options) {
+ stringify: function (data, options) {
// summary:
// Serializes data as CSV
// options: Object?
View
2  Memory.js
@@ -1,5 +1,5 @@
define(['dojo/_base/declare', 'dojo/_base/lang', 'dojo/_base/array', './SimpleQuery' /*=====, './api/Store' =====*/],
- function(declare, lang, arrayUtil, SimpleQuery /*=====, Store =====*/){
+ function (declare, lang, arrayUtil, SimpleQuery /*=====, Store =====*/) {
// module:
// dstore/Memory
View
24 Model.js
@@ -6,7 +6,7 @@ define([
'dojo/when'
], function (declare, lang, Deferred, aspect, when) {
- function getSchemaProperty (object, key) {
+ function getSchemaProperty(object, key) {
// this function will retrieve the individual property definition
// from the schema, for the provided object and key
var definition = object.schema[key];
@@ -40,7 +40,7 @@ define([
}
if (property && property.validate) {
- return when(property.validate(), function(isValid) {
+ return when(property.validate(), function (isValid) {
if (!isValid) {
// errors, so don't perform set
if (!hasOwnPropertyInstance) {
@@ -74,7 +74,7 @@ define([
// make sure we have a deferred
deferred = new Deferred();
}
- value.then(function (value){
+ value.then(function (value) {
// result received, call callback, and then indicate another item is done
doneItem(callback(value, key));
}).then(null, deferred.reject);
@@ -159,7 +159,7 @@ define([
// suppress any non-date from serialization output
object.prepareForSerialization();
return object._store && when(object._store[scenario === 'insert' ? 'add' : 'put'](object),
- function(returned) {
+ function (returned) {
if (typeof returned === 'object') {
// receive any updates from the server
object.set(returned);
@@ -293,7 +293,7 @@ define([
// we can shortcut right to just setting the object property
this[key] = value;
// check to see if we should do validation
- if (definition && definition.validateOnSet !== false){
+ if (definition && definition.validateOnSet !== false) {
validate(this, key);
}
}
@@ -331,7 +331,7 @@ define([
// check to see if we are allowed to validate this key
if (!fieldMap || (fieldMap.hasOwnProperty(key))) {
// run validation
- whenItem(validate(object, key), function (isValid, key){
+ whenItem(validate(object, key), function (isValid, key) {
if (!isValid) {
notValid(key);
}
@@ -480,17 +480,17 @@ define([
if (hasOldObject || hasNewObject) {
// we will iterate through the properties recording the changes
var changes = {};
- if (hasOldObject){
+ if (hasOldObject) {
for (key in oldValue) {
changes[key] = {old: oldValue[key]};
}
}
- if (hasNewObject){
+ if (hasNewObject) {
for (key in value) {
(changes[key] = changes[key] || {}).value = value[key];
}
}
- for(key in changes){
+ for (key in changes) {
// now for each change, we can notify the property object
var change = changes[key];
property.set(key, change.value, change.old);
@@ -554,7 +554,7 @@ define([
errors.push(value + ' is not a ' + this.type);
}
- if(this.required && !(value != null && value !== '')) {
+ if (this.required && !(value != null && value !== '')) {
errors.push('required, and it was not present');
}
return errors;
@@ -599,11 +599,11 @@ define([
});
// a function that returns a function, to stop JSON serialization of an
// object
- function toJSONHidden () {
+ function toJSONHidden() {
return toJSONHidden;
}
// An object that will be hidden from JSON serialization
- var Hidden = function() {
+ var Hidden = function () {
};
Hidden.prototype.toJSON = toJSONHidden;
View
36 Observable.js
@@ -7,7 +7,7 @@ define([
'dojo/_base/array',
'dojo/on'
/*=====, './api/Store' =====*/
-], function(lang, declare, aspect, when, whenAll, arrayUtil, on /*=====, Store =====*/){
+], function (lang, declare, aspect, when, whenAll, arrayUtil, on /*=====, Store =====*/) {
// module:
// dstore/Observable
@@ -30,7 +30,7 @@ define([
// existing range completely precedes new range. we are done.
ranges.splice(i + 1, 0, createRange(newStart, newEnd));
return;
- } else if(newEnd >= existingStart) {
+ } else if (newEnd >= existingStart) {
// the ranges overlap and must be merged into a single range
newStart = Math.min(newStart, existingStart);
newEnd = Math.max(newEnd, existingEnd);
@@ -41,16 +41,16 @@ define([
ranges.unshift(createRange(newStart, newEnd));
}
- function unregisterRange (ranges, start, end) {
+ function unregisterRange(ranges, start, end) {
for (var i = 0, range; (range = ranges[i]); ++i) {
var existingStart = range.start,
existingEnd = existingStart + range.count;
- if(start <= existingStart){
- if(end >= existingEnd){
+ if (start <= existingStart) {
+ if (end >= existingEnd) {
// The existing range is within the forgotten range
ranges.splice(i, 1);
- }else{
+ } else {
// The forgotten range overlaps the beginning of the existing range
range.start = end;
range.count = existingEnd - range.start;
@@ -59,14 +59,14 @@ define([
// there are no more ranges to update, and we are done
return;
}
- }else if(start < existingEnd){
- if(end > existingStart){
+ } else if (start < existingEnd) {
+ if (end > existingStart) {
// The forgotten range is within the existing range
ranges.splice(i, 1, createRange(existingStart, start), createRange(end, existingEnd));
// We are done because the existing range bounded the forgotten range
return;
- }else{
+ } else {
// The forgotten range overlaps the end of the existing range
range.count = start - range.start;
}
@@ -86,8 +86,8 @@ define([
// register to listen for updates
for (var type in eventTypes) {
handles.push(
- this.on(type, (function(type){
- return function(event){
+ this.on(type, (function (type) {
+ return function (event) {
notify(type, event.target || event.id, event);
};
})(type))
@@ -105,7 +105,7 @@ define([
handles.pop().remove();
}
- this.remove = function(){};
+ this.remove = function () {};
}
}
});
@@ -126,7 +126,7 @@ define([
// Treat in-memory data as one range to allow a single code path for all stores
registerRange(ranges, 0, observed.data.length);
- observed.releaseRange = function(){};
+ observed.releaseRange = function () {};
} else {
var originalRange = observed.range;
observed.range = function (start, end) {
@@ -139,7 +139,7 @@ define([
whenAll({
data: rangeCollection.fetch(),
total: rangeCollection.total
- }).then(function(result){
+ }).then(function (result) {
partialData.length = result.total;
// copy the new ranged data into the parent partial data set
@@ -152,7 +152,7 @@ define([
observed.releaseRange = function (start, end) {
unregisterRange(ranges, start, end);
- for(var i = start; i < end; ++i){
+ for (var i = start; i < end; ++i) {
delete this.partialData[i];
}
};
@@ -162,7 +162,7 @@ define([
revision++;
event = lang.delegate(event);
when(observed.hasOwnProperty('data') ? observed.data :
- observed.partialData, function(resultsArray){
+ observed.partialData, function (resultsArray) {
/* jshint maxcomplexity: 30 */
var queryExecutor = observed.queryer;
var i, j, l, range;
@@ -222,7 +222,7 @@ define([
// If the original index came from this range, put back in the original slot
// so it doesn't move unless it needs to (relying on a stable sort below)
if (removedFrom >= Math.max(0, range.start - 1) &&
- removedFrom <= (range.start + range.count)){
+ removedFrom <= (range.start + range.count)) {
sampleArray.splice(removedFrom, 0, target);
} else {
sampleArray.push(target);
@@ -233,7 +233,7 @@ define([
if (sortedIndex === 0 && range.start !== 0) {
end = i - 1;
- } else if(sortedIndex >= (sampleArray.length - 1) &&
+ } else if (sortedIndex >= (sampleArray.length - 1) &&
adjustedIndex < resultsArray.length) {
begin = i + 1;
} else {
View
4 Request.js
@@ -111,7 +111,7 @@ define([
// Constructs filter-related params to be inserted into the query string
// returns: String
// Filter-related params to be inserted in the query string
- return this.filtered && array.map(this.filtered, function(filter){
+ return this.filtered && array.map(this.filtered, function (filter) {
return typeof filter === 'object' ? ioQuery.objectToQuery(filter) : filter;
}).join('&');
},
@@ -124,7 +124,7 @@ define([
var sortString = '';
if (this.sorted) {
- sortString = array.map(this.sorted, function(sortOption) {
+ sortString = array.map(this.sorted, function (sortOption) {
var prefix = sortOption.descending ? this.descendingPrefix : this.ascendingPrefix;
return prefix + encodeURIComponent(sortOption.property);
}, this).join(',');
View
2  Rest.js
@@ -5,7 +5,7 @@ define([
'dojo/io-query',
'dojo/_base/declare',
'./Request' /*=====, './api/Store' =====*/
-], function(request, lang, JSON, ioQuery, declare, Request /*=====, Store =====*/){
+], function (request, lang, JSON, ioQuery, declare, Request /*=====, Store =====*/) {
/*=====
var __HeaderOptions = {
View
12 SimpleQuery.js
@@ -15,7 +15,7 @@ define([
filter: function (query) {
// create our matching query function
var queryer = query;
- switch(typeof query){
+ switch (typeof query) {
default:
throw new Error('Can not query with a ' + typeof query);
case 'object':
@@ -29,7 +29,7 @@ define([
if (!required.test(object[key], object)) {
return false;
}
- } else if(required !== object[key]) {
+ } else if (required !== object[key]) {
return false;
}
}
@@ -42,9 +42,9 @@ define([
throw new Error('No filter function ' + query + ' was found in store');
}
queryer = this[query];
- // fall through
+ /* falls through */
case 'function':
- // fall through
+ /* falls through */
}
return this._addQueryer(this.inherited(arguments), function (data) {
@@ -52,12 +52,13 @@ define([
});
},
+ /* jshint ignore:start */
sort: function (property) {
var newCollection = this.inherited(arguments);
return this._addQueryer(newCollection, function (data) {
var sorted = newCollection.sorted;
data.sort(typeof property === 'function' ? property : function (a, b) {
- for(var i = 0; i < sorted.length; i++){
+ for (var i = 0; i < sorted.length; i++) {
var property = sorted[i].property;
var descending = sorted[i].descending;
var aValue = a[property];
@@ -71,6 +72,7 @@ define([
return data;
});
},
+ /* jshint ignore:end */
_addQueryer: function (collection, queryer) {
var previousQueryer = this.queryer;
View
14 Store.js
@@ -30,15 +30,15 @@ define([
map: function (callback, thisObject) {
var results = [];
// like forEach, except we collect results
- return when(this.forEach(function(object, i){
+ return when(this.forEach(function (object, i) {
results.push(callback.call(thisObject, object, i));
- }, thisObject), function(){
+ }, thisObject), function () {
return results;
});
},
forEach: function (callback, thisObject) {
- return when(this.fetch(), function(data){
- for(var i = 0, l = data.length; i < l; i++){
+ return when(this.fetch(), function (data) {
+ for (var i = 0, l = data.length; i < l; i++) {
callback.call(thisObject, data[i], i);
}
return data;
@@ -47,7 +47,7 @@ define([
on: function (type, listener) {
// summary:
// Listen for data changes
- if (type !== 'refresh' && this.store && this.store !== this){
+ if (type !== 'refresh' && this.store && this.store !== this) {
return this.store.on(type, listener);
}
return this.inherited(arguments);
@@ -83,7 +83,7 @@ define([
assignPrototype: function (object) {
// Set the object's prototype
var model = this.model;
- if(model && object){
+ if (model && object) {
var prototype = model.prototype;
if (hasProto) {
// the fast easy way
@@ -128,7 +128,7 @@ define([
sorted = property;
} else if (lang.isArray(property)) {
sorted = property.slice(0);
- } else if(typeof property === 'object') {
+ } else if (typeof property === 'object') {
sorted = [].slice.call(arguments, 0);
} else {
sorted = [{
View
2  Validating.js
@@ -1,4 +1,4 @@
-define(['./Store', 'dojo/when', 'dojo/_base/declare'], function(Store, when, declare){
+define(['./Store', 'dojo/when', 'dojo/_base/declare'], function (Store, when, declare) {
// module:
// dstore/Validating
// summary:
View
9 api/Store.js
@@ -188,15 +188,6 @@ define(['dojo/_base/declare'], function (declare) {
// Deletes an object by its identity
// id: Number
// The identity to use to delete the object
- delete this.index[id];
- var data = this.data,
- idProperty = this.idProperty;
- for(var i = 0, l = data.length; i < l; i++){
- if(data[i][idProperty] === id){
- data.splice(i, 1);
- return;
- }
- }
},
transaction: function () {
// summary:
View
4 charting/StoreSeries.js
@@ -30,12 +30,12 @@ define([
}
return o;
};
- }else{
+ } else {
this.value = function (object) {
return object[value];
};
}
- }else{
+ } else {
this.value = function (object) {
return object.value;
};
View
2  legacy/StoreAdapter.js
@@ -21,7 +21,7 @@ define([
// returns: Object
// The object in the store that matches the given id.
var self = this;
- return when(this.inherited(arguments), function(object){
+ return when(this.inherited(arguments), function (object) {
return self.assignPrototype(object);
});
},
View
55 tests/Cache.js
@@ -9,12 +9,13 @@ define([
'./mockRequest',
'dojo/when',
'dstore/Cache'
-], function(registerSuite, assert, Deferred, declare, Store, Memory, Request, mockRequest, when, Cache){
+], function (registerSuite, assert, Deferred, declare, Store, Memory, Request, mockRequest, when, Cache) {
+ /* jshint newcap: false */
var cachingStore = new Memory();
var masterFilterCalled;
var MasterStore = declare([Memory], {
- filter: function(){
+ filter: function () {
masterFilterCalled = true;
return this.inherited(arguments);
}
@@ -33,7 +34,7 @@ define([
registerSuite({
name: 'dstore Cache',
- 'get': function(){
+ 'get': function () {
assert.strictEqual(store.get(1).name, 'one');
assert.strictEqual(cachingStore.get(1).name, 'one'); // second one should be cached
assert.strictEqual(store.get(1).name, 'one');
@@ -42,26 +43,26 @@ define([
assert.strictEqual(store.get(4).name, 'four');
},
- 'filter': function(){
- store.isLoaded = store.canCacheQuery = function(){
+ 'filter': function () {
+ store.isLoaded = store.canCacheQuery = function () {
return false;
};
assert.strictEqual(store.filter({prime: true}).fetch().length, 3);
assert.strictEqual(store.filter({even: true}).fetch()[1].name, 'four');
assert.strictEqual(cachingStore.get(3), undefined);
- store.isLoaded = store.canCacheQuery = function(){
+ store.isLoaded = store.canCacheQuery = function () {
return true;
};
assert.strictEqual(store.filter({prime: true}).fetch().length, 3);
assert.strictEqual(cachingStore.get(3).name, 'three');
},
- 'filter with sort': function(){
+ 'filter with sort': function () {
assert.strictEqual(store.filter({prime: true}).sort('name').fetch().length, 3);
assert.strictEqual(store.filter({even: true}).sort('name').fetch()[1].name, 'two');
},
- 'put update': function(){
+ 'put update': function () {
var four = store.get(4);
four.square = true;
store.put(four);
@@ -73,7 +74,7 @@ define([
assert.isTrue(four.square);
},
- 'put new': function(){
+ 'put new': function () {
store.put({
id: 6,
perfect: true
@@ -82,20 +83,20 @@ define([
assert.isTrue(cachingStore.get(6).perfect);
},
- 'add duplicate': function(){
+ 'add duplicate': function () {
var threw;
- try{
+ try {
store.add({
id: 6,
perfect: true
});
- }catch(e){
+ } catch (e) {
threw = true;
}
assert.isTrue(threw);
},
- 'add new': function(){
+ 'add new': function () {
store.add({
id: 7,
prime: true
@@ -104,20 +105,20 @@ define([
assert.isTrue(cachingStore.get(7).prime);
},
- 'cached filter': function(){
+ 'cached filter': function () {
store.fetch(); // should result in everything being cached
masterFilterCalled = false;
assert.strictEqual(store.filter({prime: true}).fetch().length, 4);
assert.isFalse(masterFilterCalled);
},
- 'delayed cached filter': function(){
+ 'delayed cached filter': function () {
var fetchCalled;
var MasterCollection = declare(Store, {
- fetch: function(){
+ fetch: function () {
fetchCalled = true;
var def = new Deferred();
- setTimeout(function(){
+ setTimeout(function () {
def.resolve([
{id: 1, name: 'one', prime: false},
{id: 2, name: 'two', even: true, prime: true},
@@ -135,35 +136,35 @@ define([
fetchCalled = false;
var testDef = new Deferred();
var count = 0;
- store.filter({prime: true}).forEach(function(){
+ store.filter({prime: true}).forEach(function () {
count++;
- }).then(function(){
+ }).then(function () {
assert.strictEqual(count, 3);
assert.isFalse(fetchCalled);
testDef.resolve(true);
});
return testDef;
},
- 'like RequestMemory': function(){
+ 'like RequestMemory': function () {
var store = new declare([Request, Cache], {
- constructor: function(){
+ constructor: function () {
this.fetch();
}
})({
target: require.toUrl('dstore/tests/data/treeTestRoot')
});
- store.get('node3').then(function(object){
+ store.get('node3').then(function (object) {
assert.strictEqual(JSON.stringify(object), JSON.stringify({ id: 'node3', name:'node3', someProperty:'somePropertyC'}));
});
var results = [];
- return store.filter({name: 'node2'}).forEach(function(object){
+ return store.filter({name: 'node2'}).forEach(function (object) {
results.push(object);
- }).then(function(){
+ }).then(function () {
assert.strictEqual(JSON.stringify(results), JSON.stringify([{ id: 'node2', name:'node2', someProperty:'somePropertyB'}]));
- return store.get('node3').then(function(object){
+ return store.get('node3').then(function (object) {
object.changed = true;
- return when(store.put(object), function(){
- return when(store.get('node3'), function(object){
+ return when(store.put(object), function () {
+ return when(store.get('node3'), function (object) {
assert.strictEqual(JSON.stringify(object),
JSON.stringify({ id: 'node3', name:'node3', someProperty:'somePropertyC', changed: true}));
});
View
16 tests/Csv.js
@@ -7,7 +7,7 @@ define([
'dstore/Csv',
'dstore/Memory'
],
- function(registerSuite, assert, request, all, declare, Csv, Memory){
+ function (registerSuite, assert, request, all, declare, Csv, Memory) {
var CsvMemory = declare([Memory, Csv]);
var xhrBase = require.toUrl('dstore/tests/data');
var csvs = {}; // holds retrieved raw CSV data
@@ -16,7 +16,7 @@ define([
// Load CSV data. The referenced data has various inconsistencies
// throughout on purpose, to test that the implementation responds
// properly to things like extra whitespace, blank values/lines, etc.
- request(xhrBase + '/noquote.csv').then(function(data){
+ request(xhrBase + '/noquote.csv').then(function (data) {
csvs.noQuote = data;
stores.noQuoteNoHeader = new CsvMemory({
data: data,
@@ -34,7 +34,7 @@ define([
trim: true
});
}),
- request(xhrBase + '/quote.csv').then(function(data){
+ request(xhrBase + '/quote.csv').then(function (data) {
csvs.quote = data;
stores.quoteNoHeader = new CsvMemory({
data: data,
@@ -47,7 +47,7 @@ define([
// No fieldNames; first row will be treated as header row.
});
}),
- request(xhrBase + '/contributors.csv').then(function(data){
+ request(xhrBase + '/contributors.csv').then(function (data) {
csvs.contributors = data;
stores.contributors = new CsvMemory({
data: data,
@@ -56,11 +56,11 @@ define([
})
]);
- readyPromise.then(function(){
+ readyPromise.then(function () {
registerSuite({
name: 'dstore CSV',
- 'no quote': function(){
+ 'no quote': function () {
var noHeader = stores.noQuoteNoHeader,
withHeader = stores.noQuoteWithHeader,
trim = stores.noQuoteTrim,
@@ -101,7 +101,7 @@ define([
assert.isTrue(withHeader.get('3').died === '', 'Test blank value at end of line.');
},
- 'quote': function(){
+ 'quote': function () {
var noHeader = stores.quoteNoHeader,
withHeader = stores.quoteWithHeader;
@@ -126,7 +126,7 @@ define([
'Multiline value should use same newline format as input.');
},
- 'import export': function(){
+ 'import export': function () {
assert.strictEqual(csvs.contributors, stores.contributors.toCsv(),
'toCsv() should generate data matching original if it is well-formed');
}
View
78 tests/Memory.js
@@ -3,16 +3,16 @@ define([
'intern/chai!assert',
'dojo/_base/declare',
'dstore/Memory'
-], function(registerSuite, assert, declare, Memory){
+], function (registerSuite, assert, declare, Memory) {
var store;
- function passThrough(object){ return object; }
+ function passThrough(object) { return object; }
registerSuite({
name: 'dstore Memory',
- beforeEach: function(){
+ beforeEach: function () {
store = new Memory({
data: [
{id: 1, name: 'one', prime: false, mappedTo: 'E'},
@@ -24,73 +24,73 @@ define([
});
// add a method to the model prototype
- store.model.prototype.describe = function(){
+ store.model.prototype.describe = function () {
return this.name + ' is ' + (this.prime ? '' : 'not ') + 'a prime';
};
},
- 'get': function(){
+ 'get': function () {
assert.strictEqual(store.get(1).name, 'one');
assert.strictEqual(store.get(4).name, 'four');
assert.isTrue(store.get(5).prime);
},
- 'model': function(){
+ 'model': function () {
assert.strictEqual(store.get(1).describe(), 'one is not a prime');
assert.strictEqual(store.get(3).describe(), 'three is a prime');
assert.strictEqual(store.filter({even: true}).data[1].describe(), 'four is not a prime');
},
- 'query': function(){
+ 'query': function () {
assert.strictEqual(store.filter({prime: true}).data.length, 3);
assert.strictEqual(store.filter({even: true}).data[1].name, 'four');
},
- 'query with string': function(){
+ 'query with string': function () {
assert.strictEqual(store.filter({name: 'two'}).data.length, 1);
assert.strictEqual(store.filter({name: 'two'}).data[0].name, 'two');
},
- 'query with regexp': function(){
+ 'query with regexp': function () {
assert.strictEqual(store.filter({name: /^t/}).data.length, 2);
assert.strictEqual(store.filter({name: /^t/}).data[1].name, 'three');
assert.strictEqual(store.filter({name: /^o/}).data.length, 1);
assert.strictEqual(store.filter({name: /o/}).data.length, 3);
},
- 'query with test function': function(){
- assert.strictEqual(store.filter({id: {test: function(id){
+ 'query with test function': function () {
+ assert.strictEqual(store.filter({id: {test: function (id) {
return id < 4;
}}}).data.length, 3);
- assert.strictEqual(store.filter({even: {test: function(even, object){
+ assert.strictEqual(store.filter({even: {test: function (even, object) {
return even && object.id > 2;
}}}).data.length, 1);
},
- 'query with sort': function(){
+ 'query with sort': function () {
assert.strictEqual(store.filter({prime: true}).sort('name').data.length, 3);
assert.strictEqual(store.filter({even: true}).sort('name').data[1].name, 'two');
- assert.strictEqual(store.filter({even: true}).sort(function(a, b){
+ assert.strictEqual(store.filter({even: true}).sort(function (a, b) {
return a.name < b.name ? -1 : 1;
}).data[1].name, 'two');
assert.strictEqual(store.filter(null).sort('mappedTo').data[4].name, 'four');
},
- 'query with paging': function(){
+ 'query with paging': function () {
assert.strictEqual(store.filter({prime: true}).range(1, 2).data.length, 1);
assert.strictEqual(store.filter({even: true}).range(1, 2).data[0].name, 'four');
},
- 'query with inheritance': function(){
+ 'query with inheritance': function () {
var store = new Memory({
data: [
{id: 1, name: 'one', prime: false},
{id: 2, name: 'two', even: true, prime: true}
],
- getIdentity: function(){
+ getIdentity: function () {
return 'id-' + this.inherited(arguments);
},
- newMethod: function(){
+ newMethod: function () {
return 'hello';
}
});
@@ -104,7 +104,7 @@ define([
assert.strictEqual(filtered.get(1), undefined);
},
- 'put update': function(){
+ 'put update': function () {
var four = store.get(4);
four.square = true;
store.put(four);
@@ -112,7 +112,7 @@ define([
assert.isTrue(four.square);
},
- save: function(){
+ save: function () {
var four = store.get(4);
four.square = true;
four.save();
@@ -120,7 +120,7 @@ define([
assert.isTrue(four.square);
},
- 'put new': function(){
+ 'put new': function () {
store.put({
id: 6,
perfect: true
@@ -128,7 +128,7 @@ define([
assert.isTrue(store.get(6).perfect);
},
- 'create and remove': function(){
+ 'create and remove': function () {
var newObject = store.create({
id: 10,
name: 'ten'
@@ -141,7 +141,7 @@ define([
assert.isNotObject(store.get(10));
},
- 'add duplicate': function(){
+ 'add duplicate': function () {
store.put({
id: 6,
perfect: true
@@ -153,13 +153,13 @@ define([
id: 6,
perfect: true
});
- }catch(e){
+ }catch(e) {
threw = true;
}
assert.isTrue(threw);
},
- 'add new': function(){
+ 'add new': function () {
store.add({
id: 7,
prime: true
@@ -167,7 +167,7 @@ define([
assert.isTrue(store.get(7).prime);
},
- 'remove': function(){
+ 'remove': function () {
store.add({
id: 7,
prime: true
@@ -176,7 +176,7 @@ define([
assert.strictEqual(store.get(7), undefined);
},
- 'remove from object': function(){
+ 'remove from object': function () {
var newObject = store.add({
id: 7,
prime: true
@@ -185,21 +185,21 @@ define([
assert.strictEqual(store.get(7), undefined);
},
- 'remove missing': function(){
+ 'remove missing': function () {
var expectedLength = store.data.length;
assert(!store.remove(77));
// make sure nothing changed
assert.strictEqual(store.data.length, expectedLength);
},
- 'query after changes': function(){
+ 'query after changes': function () {
store.remove(2);
store.add({ id: 6, perfect: true });
assert.strictEqual(store.filter({prime: true}).data.length, 2);
assert.strictEqual(store.filter({perfect: true}).data.length, 1);
},
- 'ifrs style data': function(){
+ 'ifrs style data': function () {
var anotherStore = new Memory({
data: {
@@ -215,7 +215,7 @@ define([
assert.strictEqual(anotherStore.filter({name: 'one'}).data[0].name, 'one');
},
- 'add new id assignment': function(){
+ 'add new id assignment': function () {
var object = {
random: true
};
@@ -223,14 +223,14 @@ define([
assert.isTrue(!!object.id);
},
- 'total property': function(){
- var filteredCollection = store.filter(function(o){
+ 'total property': function () {
+ var filteredCollection = store.filter(function (o) {
return o.id <= 3;
});
assert.property(filteredCollection, 'total');
assert.strictEqual(filteredCollection.total, filteredCollection.data.length);
- var sortedCollection = store.sort("id");
+ var sortedCollection = store.sort('id');
assert.strictEqual(sortedCollection.total, sortedCollection.data.length);
var rangedCollection = store.range(0, 3);
@@ -242,7 +242,7 @@ define([
registerSuite({
name: 'dstore Memory sorting',
- before: function(){
+ before: function () {
store = new Memory({
data: [
{id: 1, field1: 'one', field2: '1'},
@@ -255,7 +255,7 @@ define([
});
},
- 'multiple sort fields - ascend + ascend': function(){
+ 'multiple sort fields - ascend + ascend': function () {
var results = store.sort({property: 'field1'},
{property: 'field2'}).fetch();
@@ -276,7 +276,7 @@ define([
assert.strictEqual(results[5].id, 3);
},
- 'multiple sort fields - ascend + descend': function(){
+ 'multiple sort fields - ascend + descend': function () {
var results = store.sort({property: 'field1', descending: false},
{property: 'field2', descending: true}).map(passThrough);
@@ -297,7 +297,7 @@ define([
assert.strictEqual(results[5].id, 5);
},
- 'multiple sort fields - descend + ascend': function(){
+ 'multiple sort fields - descend + ascend': function () {
var results = store.sort({property: 'field1', descending: true},
{property: 'field2', descending: false}).map(passThrough);
@@ -318,7 +318,7 @@ define([
assert.strictEqual(results[5].id, 6);
},
- 'multiple sort fields - descend + descend': function(){
+ 'multiple sort fields - descend + descend': function () {
var results = store.sort({property: 'field1',descending: true},
{property: 'field2', descending: true}).map(passThrough);
View
6 tests/Model.js
@@ -172,7 +172,7 @@ define([
required: true
}),
range: new Property({
- checkForErrors: function(value) {
+ checkForErrors: function (value) {
var errors = this.inherited(arguments);
if (value < 10 || value > 20) {
errors.push('not in range');
@@ -191,7 +191,7 @@ define([
model.set('range', 15);
assert.isTrue(model.validate());
var lastReceivedErrors;
- model.property('range').property('errors').observe(function(errors){
+ model.property('range').property('errors').observe(function (errors) {
lastReceivedErrors = errors;
});
model.set('requiredString', '');
@@ -248,7 +248,7 @@ define([
model.set('firstName', 'Jane');
assert.strictEqual(updatedName, 'Jane Doe');
var updatedName2;
- var handle = model.property('name').observe(function(name){
+ var handle = model.property('name').observe(function (name) {
updatedName2 = name;
});
assert.strictEqual(updatedName2, 'Jane Doe');
View
110 tests/Observable.js
@@ -9,10 +9,10 @@ define([
'dstore/Store',
'dstore/Observable',
'dstore/SimpleQuery'
-], function(registerSuite, assert, arrayUtil, declare, lang, when, Memory, Store, Observable, SimpleQuery){
+], function (registerSuite, assert, arrayUtil, declare, lang, when, Memory, Store, Observable, SimpleQuery) {
var MyStore = declare([Memory, Observable], {
- get: function(){
+ get: function () {
// need to make sure that this.inherited still works with Observable
return this.inherited(arguments);
}
@@ -29,32 +29,32 @@ define([
});
// TODO: Maybe name this differently
- function createBigStore(numItems, Store){
+ function createBigStore(numItems, Store) {
var data = [];
var i;
- for(i = 0; i < numItems; i++){
+ for (i = 0; i < numItems; i++) {
data.push({id: i, name: 'item ' + i, order: i});
}
return new Store({data: data});
}
// A store for testing Observable with only partial in-memory data
- var ObservablePartialDataStore = declare([ Store, Observable, SimpleQuery ], (function(){
+ var ObservablePartialDataStore = declare([ Store, Observable, SimpleQuery ], (function () {
var proto = {
- constructor: function(kwArgs){
+ constructor: function (kwArgs) {
delete this.data;
this.backingMemoryStore = new MyStore(kwArgs);
}
};
- arrayUtil.forEach(['getIdentity', 'get', 'add', 'put', 'remove'], function(method){
- proto[method] = function(){
+ arrayUtil.forEach(['getIdentity', 'get', 'add', 'put', 'remove'], function (method) {
+ proto[method] = function () {
return this.backingMemoryStore[method].apply(this.backingMemoryStore, arguments);
};
});
- arrayUtil.forEach(['filter', 'sort', 'range'], function(method){
- proto[method] = function(){
+ arrayUtil.forEach(['filter', 'sort', 'range'], function (method) {
+ proto[method] = function () {
var newBackingStore = this.backingMemoryStore[method].apply(this.backingMemoryStore, arguments);
return lang.mixin(this.inherited(arguments), {
backingMemoryStore: newBackingStore
@@ -63,16 +63,16 @@ define([
});
// Make backing store an observed collection so its data is kept up-to-date
- proto.track = function(){
- this.backingMemoryStore = this.backingMemoryStore.track(function(){});
+ proto.track = function () {
+ this.backingMemoryStore = this.backingMemoryStore.track(function () {});
return this.inherited(arguments);
};
// Make events go to backing store
- proto.on = function(type, listener){
+ proto.on = function (type, listener) {
return this.backingMemoryStore.on(type, listener);
};
- proto.fetch = function(){
+ proto.fetch = function () {
this.data = when(this.backingMemoryStore.fetch());
this.total = when(this.backingMemoryStore.total);
return this.data;
@@ -84,34 +84,34 @@ define([
registerSuite({
name: 'dstore Observable',
- 'get': function(){
+ 'get': function () {
assert.strictEqual(store.get(1).name, 'one');
assert.strictEqual(store.get(4).name, 'four');
assert.isTrue(store.get(5).prime);
},
- 'filter': function(){
+ 'filter': function () {
var results = store.filter({prime: true});
assert.strictEqual(results.data.length, 3);
var changes = [], secondChanges = [];
var tracked = results.track();
- tracked.on('update', function(event){
+ tracked.on('update', function (event) {
changes.push(event);
});
- tracked.on('remove', function(event){
+ tracked.on('remove', function (event) {
changes.push(event);
});
- tracked.on('add', function(event){
+ tracked.on('add', function (event) {
changes.push(event);
});
- var secondObserverUpdate = tracked.on('update', function(event){
+ var secondObserverUpdate = tracked.on('update', function (event) {
secondChanges.push(event);
});
- var secondObserverRemove = tracked.on('remove', function(event){
+ var secondObserverRemove = tracked.on('remove', function (event) {
secondChanges.push(event);
});
- var secondObserverAdd = tracked.on('add', function(event){
+ var secondObserverAdd = tracked.on('add', function (event) {
secondChanges.push(event);
});
var expectedChanges = [],
@@ -142,7 +142,7 @@ define([
});
assert.strictEqual(tracked.data.length, 3);
// shouldn't be added
- var six = {id:6, name:'six'};
+ var six = {id: 6, name: 'six'};
store.add(six);
assert.strictEqual(tracked.data.length, 3);
@@ -154,7 +154,7 @@ define([
});
// should be added
- var seven = {id:7, name:'seven', prime:true};
+ var seven = {id: 7, name: 'seven', prime: true};
store.add(seven);
assert.strictEqual(tracked.data.length, 4);
@@ -175,12 +175,12 @@ define([
assert.deepEqual(changes, expectedChanges);
},
- 'filter with zero id': function(){
+ 'filter with zero id': function () {
var results = store.filter({});
results.fetch();
assert.strictEqual(results.data.length, 7);
var tracked = results.track();
- tracked.on('update', function(event){
+ tracked.on('update', function (event) {
// we only do puts so previous & new indices must always been the same
assert.ok(event.index === event.previousIndex);
});
@@ -188,29 +188,29 @@ define([
store.put({id: 0, name: '-ZERO-', prime: false});
},
- 'paging with store.data': function(){
+ 'paging with store.data': function () {
var results,
bigStore = createBigStore(100, MyStore),
bigFiltered = bigStore.filter({}).sort('order');
var observations = [];
var bigObserved = bigFiltered.track();
- bigObserved.on('update', function(event){
+ bigObserved.on('update', function (event) {
observations.push(event);
console.log(' observed: ', event);
});
- bigObserved.on('add', function(event){
+ bigObserved.on('add', function (event) {
observations.push(event);
console.log(' observed: ', event);
});
- bigObserved.on('remove', function(event){
+ bigObserved.on('remove', function (event) {
observations.push(event);
console.log(' observed: ', event);
});
- bigObserved.range(0,25).fetch();
- bigObserved.range(25,50).fetch();
- bigObserved.range(50,75).fetch();
- bigObserved.range(75,100).fetch();
+ bigObserved.range(0, 25).fetch();
+ bigObserved.range(25, 50).fetch();
+ bigObserved.range(50, 75).fetch();
+ bigObserved.range(75, 100).fetch();
bigObserved.fetch();
var results = bigObserved.data;
@@ -226,32 +226,32 @@ define([
},
// TODO: Consider breaking this down into smaller test cases
- 'paging with store.partialData': function(){
+ 'paging with store.partialData': function () {
var bigStore = createBigStore(100, ObservablePartialDataStore),
bigFiltered = bigStore.filter({}).sort('order'),
latestObservation,
bigObserved = bigFiltered.track(),
item,
- assertObservationIs = function(expectedObservation){
+ assertObservationIs = function (expectedObservation) {
expectedObservation = lang.delegate(expectedObservation);
- if(expectedObservation.type in { add: 1, update: 1 }
- && !('index' in expectedObservation)){
+ if (expectedObservation.type in { add: 1, update: 1 }
+ && !('index' in expectedObservation)) {
expectedObservation.index = undefined;
}
- if(expectedObservation.type in { update: 1, remove: 1 }
- && !('previousIndex' in expectedObservation)){
+ if (expectedObservation.type in { update: 1, remove: 1 }
+ && !('previousIndex' in expectedObservation)) {
expectedObservation.previousIndex = undefined;
}
assert.deepEqual(latestObservation, expectedObservation);
};
- bigObserved.on('update', function(event){
+ bigObserved.on('update', function (event) {
latestObservation = event;
});
- bigObserved.on('add', function(event){
+ bigObserved.on('add', function (event) {
latestObservation = event;
});
- bigObserved.on('remove', function(event){
+ bigObserved.on('remove', function (event) {
latestObservation = event;
});
// TODO: Fix names bigXyz names. Probably use the term collection instead of store for return value of filter and sort
@@ -364,7 +364,7 @@ define([
assertObservationIs({ type: 'add', target: item });
},
- 'paging releaseRange with store.partialData': function(){
+ 'paging releaseRange with store.partialData': function () {
var itemCount = 100,
store = createBigStore(itemCount, ObservablePartialDataStore),
rangeToBeEclipsed = { start: 5, end: 15 },
@@ -378,13 +378,13 @@ define([
var observations = [],
trackedStore = store.track(),
- assertRangeDefined = function(start, end){
- for(var i = start; i < end; ++i){
+ assertRangeDefined = function (start, end) {
+ for(var i = start; i < end; ++i) {
assert.notEqual(trackedStore.partialData[i], undefined);
}
},
- assertRangeUndefined = function(start, end){
- for(var i = start; i < end; ++i){
+ assertRangeUndefined = function (start, end) {
+ for(var i = start; i < end; ++i) {
assert.equal(trackedStore.partialData[i], undefined);
}
};
@@ -418,13 +418,13 @@ define([
assertRangeUndefined(tailTrimmingRange.start, tailTrimmingRange.end);
},
- 'new item with default index': function(){
+ 'new item with default index': function () {
var store = createBigStore(100, ObservablePartialDataStore),
trackedStore = store.track();
- return trackedStore.range(0, 25).fetch().then(function(){
+ return trackedStore.range(0, 25).fetch().then(function () {
var addEvent = null;
- trackedStore.on('add', function(event){
+ trackedStore.on('add', function (event) {
addEvent = event;
});
@@ -449,18 +449,18 @@ define([
});
},
- 'type': function(){
- assert.isFalse(store === store.track(function(){}));
+ 'type': function () {
+ assert.isFalse(store === store.track(function () {}));
},
- 'track and collection.tracking.remove': function(){
+ 'track and collection.tracking.remove': function () {
var store = createBigStore(10, declare([ Memory, Observable ])),
trackedCollection = store.track();
assert.property(trackedCollection, 'tracking');
var lastEvent = null;
- trackedCollection.on('add, update', function(event){
+ trackedCollection.on('add, update', function (event) {
lastEvent = event;
});
View
82 tests/Rest.js
@@ -11,7 +11,7 @@ define([
'./mockRequest',
'dojo/text!./data/node1.1',
'dojo/text!./data/treeTestRoot'
-], function(
+], function (
registerSuite,
assert,
declare,
@@ -24,32 +24,32 @@ define([
mockRequest,
nodeData_1_1,
treeTestRootData
-){
+) {
- function runHeaderTest(method, args){
- return store[method].apply(store, args).then(function(){
+ function runHeaderTest(method, args) {
+ return store[method].apply(store, args).then(function () {
mockRequest.assertRequestHeaders(requestHeaders);
mockRequest.assertRequestHeaders(globalHeaders);
});
}
- function runCollectionTest(collection, expected){
+ function runCollectionTest(collection, expected) {
var expectedResults = [
{ id: 1, name: 'one' },
{ id: 2, name: 'two' }
];
mockRequest.setResponseText(collection.stringify(expectedResults));
- return when(collection.fetch()).then(function(results){
+ return when(collection.fetch()).then(function (results) {
expected.headers && mockRequest.assertRequestHeaders(expected.headers);
expected.queryParams && mockRequest.assertQueryParams(expected.queryParams);
// We cannot just assert deepEqual with results and expectedResults
// because the store converts results into model instances with additional members.
assert.strictEqual(results.length, expectedResults.length);
- for(var i = 0; i < results.length; ++i){
+ for(var i = 0; i < results.length; ++i) {
var result = results[i],
expectedResult = expectedResults[i];
- for(var key in expectedResult){
+ for(var key in expectedResult) {
assert.strictEqual(result[key], expectedResult[key]);
}
}
@@ -73,40 +73,40 @@ define([
registerSuite({
name: 'dstore Rest',
- before: function(){
+ before: function () {
registryHandle = request.register(/.*mockRequest.*/, mockRequest);
},
- after: function(){
+ after: function () {
registryHandle.remove();
},
- beforeEach: function(){
+ beforeEach: function () {
mockRequest.setResponseText('{}');
mockRequest.setResponseHeaders({});
store = new Rest({
target: '/mockRequest/',
headers: globalHeaders
});
- store.model.prototype.describe = function(){
+ store.model.prototype.describe = function () {
return 'name is ' + this.name;
};
},
- 'get': function(){
+ 'get': function () {
mockRequest.setResponseText(nodeData_1_1);
- return store.get('data/node1.1').then(function(object){
+ return store.get('data/node1.1').then(function (object) {
assert.strictEqual(object.name, 'node1.1');
assert.strictEqual(object.describe(), 'name is node1.1');
assert.strictEqual(object.someProperty, 'somePropertyA1');
});
},
- 'query': function(){
+ 'query': function () {
mockRequest.setResponseText(treeTestRootData);
- return when(store.filter('data/treeTestRoot').fetch()).then(function(results){
+ return when(store.filter('data/treeTestRoot').fetch()).then(function (results) {
var object = results[0];
assert.strictEqual(object.name, 'node1');
assert.strictEqual(object.describe(), 'name is node1');
@@ -114,11 +114,11 @@ define([
});
},
- 'query iterative': function(){
+ 'query iterative': function () {
mockRequest.setResponseText(treeTestRootData);
var i = 0;
- return store.filter('data/treeTestRoot').forEach(function(object){
+ return store.filter('data/treeTestRoot').forEach(function (object) {
i++;
assert.strictEqual(object.name, 'node' + i);
// the intrinsic methods
@@ -129,19 +129,19 @@ define([
});
},
- 'headers get 1': function(){
+ 'headers get 1': function () {
return runHeaderTest('get', [ 'mockRequest/1', requestHeaders ]);
},
- 'headers get 2': function(){
+ 'headers get 2': function () {
return runHeaderTest('get', [ 'mockRequest/2', { headers: requestHeaders } ]);
},
- 'headers remove': function(){
+ 'headers remove': function () {
return runHeaderTest('remove', [ 'mockRequest/3', { headers: requestHeaders } ]);
},
- 'headers put': function(){
+ 'headers put': function () {
return runHeaderTest('put', [
{},
{
@@ -151,7 +151,7 @@ define([
]);
},
- 'headers add': function(){
+ 'headers add': function () {
return runHeaderTest('add', [
{},
{
@@ -161,41 +161,41 @@ define([
]);
},
- 'put object without ID': function(){
+ 'put object without ID': function () {
var objectWithoutId = { name: 'one' };
mockRequest.setResponseText(store.stringify(objectWithoutId));
- return store.put(objectWithoutId).then(function(){
+ return store.put(objectWithoutId).then(function () {
mockRequest.assertHttpMethod('POST');
});
},
- 'put object with ID': function(){
+ 'put object with ID': function () {
var objectWithId = { id: 1, name: 'one' };
mockRequest.setResponseText(store.stringify(objectWithId));
- return store.put(objectWithId).then(function(){
+ return store.put(objectWithId).then(function () {
mockRequest.assertHttpMethod('PUT');
});
},
- 'get and save': function(){
+ 'get and save': function () {
var expectedObject = { id: 1, name: 'one' };
mockRequest.setResponseText(store.stringify(expectedObject));
- return store.get('anything').then(function(object){
+ return store.get('anything').then(function (object) {
expectedObject.scenario = 'update';
expectedObject.saved = true;
mockRequest.setResponseText(store.stringify(expectedObject));
- return object.save().then(function(result){
+ return object.save().then(function (result) {
assert.deepEqual(store.stringify(result), store.stringify(expectedObject));
});
});
},
- 'filter': function(){
+ 'filter': function () {
var filter = { prop1: 'Prop1Value', prop2: 'Prop2Value' };
return runCollectionTest(store.filter(filter), { queryParams: filter });
},
- 'sort': function(){
+ 'sort': function () {
var sortedCollection = store.sort({
property: 'prop1',
descending: true
@@ -212,7 +212,7 @@ define([
});
},
- 'sort with this.sortParam': function(){
+ 'sort with this.sortParam': function () {
store.sortParam = 'sort-param';
var sortedCollection = store.sort({
@@ -231,7 +231,7 @@ define([
});
},
- 'sort with different prefixes': function(){
+ 'sort with different prefixes': function () {
store.descendingPrefix = '--';
store.ascendingPrefix = '++';
@@ -251,7 +251,7 @@ define([
});
},
- 'range': function(){
+ 'range': function () {
var rangeCollection = store.range(15, 25);
return runCollectionTest(rangeCollection, {
queryParams: {
@@ -260,7 +260,7 @@ define([
});
},
- 'range without end': function(){
+ 'range without end': function () {
var rangeCollection = store.range(15);
return runCollectionTest(rangeCollection, {
queryParams: {
@@ -269,7 +269,7 @@ define([
});
},
- 'filter+sort+range': function(){
+ 'filter+sort+range': function () {
var filter = { prop1: 'Prop1Value', prop2: 'Prop2Value' };
var collection = store.filter(filter).sort('prop1').range(15, 25);
return runCollectionTest(collection, {
@@ -280,7 +280,7 @@ define([
});
},
- 'composition with SimpleQuery': function(){
+ 'composition with SimpleQuery': function () {
var RestWithSimpleQuery = declare([ Rest, SimpleQuery ], {
target: '/mockRequest/'
});
@@ -296,7 +296,7 @@ define([
filteredCollection = store.filter(filter),
sortedCollection,
rangeCollection;
- return when(filteredCollection.fetch()).then(function(results){
+ return when(filteredCollection.fetch()).then(function (results) {
mockRequest.assertQueryParams(filter);
assert.strictEqual(results.length, expectedResults.length);
@@ -309,7 +309,7 @@ define([
sortedCollection = filteredCollection.sort('id', true);
return sortedCollection.fetch();
- }).then(function(results){
+ }).then(function (results) {
mockRequest.assertQueryParams({ 'sort(-id)': '' });
assert.strictEqual(results.length, expectedResults.length);
@@ -320,7 +320,7 @@ define([
rangeCollection = sortedCollection.range(15, 25);
return rangeCollection.fetch();
- }).then(function(results){
+ }).then(function (results) {
mockRequest.assertQueryParams({
'sort(-id)': '',
'range(15,25)': ''
View
18 tests/SimpleQuery.js
@@ -3,11 +3,11 @@ define([
'dojo/_base/declare',
'intern!object',
'intern/chai!assert'
-], function(SimpleQuery, declare, registerSuite, assert){
+], function (SimpleQuery, declare, registerSuite, assert) {
var Base = declare(null, {
- filter: function() { return {}; },
- sort: function() { return {}; },
- range: function() { return {}; }
+ filter: function () { return {}; },
+ sort: function () { return {}; },
+ range: function () { return {}; }
}),
TestStore = declare([ Base, SimpleQuery ], {}),
testData = [
@@ -20,15 +20,15 @@ define([
registerSuite({
name: 'dstore SimpleQuery',
- beforeEach: function(){
+ beforeEach: function () {
store = new TestStore();
},
- 'filter': function(){
- store.testFilter = function(o) { return !o.odd; };
+ 'filter': function () {
+ store.testFilter = function (o) { return !o.odd; };
var filterObject = { odd: true },
- filterFunction = function filterFunc(o){ return o.id >= 2; },
+ filterFunction = function filterFunc(o) { return o.id >= 2; },
filterIdentifier = 'testFilter',
filteredCollection;
@@ -54,7 +54,7 @@ define([
);
},
- 'sort': function(){
+ 'sort': function () {
var expectedSort1 = { attribute: 'id', descending: true },
expectedSort2 = { attribute: 'odd', descending: false },
expectedSort3 = { attribute: 'name' },
View
14 tests/Store.js
@@ -2,19 +2,19 @@ define([
'../Store',
'intern!object',
'intern/chai!assert'
-], function(Store, registerSuite, assert){
+], function (Store, registerSuite, assert) {
var store;
registerSuite({
name: 'dstore Store',
- beforeEach: function(){
+ beforeEach: function () {
store = new Store();
},
- 'filter': function(){
+ 'filter': function () {
var expectedFilter1 = { prop1: 'one' },
- expectedFilter2 = function filterFunc(){},
+ expectedFilter2 = function filterFunc() {},
filteredCollection;
filteredCollection = store.filter(expectedFilter1);
@@ -24,10 +24,10 @@ define([
assert.deepEqual(filteredCollection.filtered, [ expectedFilter1, expectedFilter2 ]);
},
- 'sort': function(){
+ 'sort': function () {
var sortObject = { property: 'prop1', descending: true },
sortObjectArray = [ sortObject, { property: 'prop2', descending: false } ],
- comparator = function comparator(){},
+ comparator = function comparator() {},
sortedCollection;
sortedCollection = store.sort(sortObject.property, sortObject.descending);
@@ -43,7 +43,7 @@ define([
assert.deepEqual(sortedCollection.sorted, comparator);
},
- 'range': function(){
+ 'range': function () {
var expectedRange1 = { start: 10, end: 20 },
expectedRange2 = { start: 25 },
rangedCollection;
View
2  tests/all.js
@@ -12,5 +12,5 @@ define([
'intern/node_modules/dojo/has!host-browser?./charting/StoreSeries',
'intern/node_modules/dojo/has!host-browser?./legacy/StoreAdapter-Memory',
'intern/node_modules/dojo/has!host-browser?./legacy/StoreAdapter-JsonRest'
-], function(){
+], function () {
});
View
56 tests/legacy/DstoreAdapter-Memory.js
@@ -4,7 +4,7 @@ define([
'intern/chai!assert',
'dstore/Memory',
'dstore/legacy/DstoreAdapter'
-], function(declare, registerSuite, assert, Memory, DstoreAdapter){
+], function (declare, registerSuite, assert, Memory, DstoreAdapter) {
var store;
@@ -13,7 +13,7 @@ define([
registerSuite({
name: 'legacy dstore adapter - Memory',
- beforeEach: function(){
+ beforeEach: function () {
store = new AdaptedDstoreMemory({
data: [
{id: 1, name: 'one', prime: false, mappedTo: 'E'},
@@ -25,96 +25,96 @@ define([
});
},
- 'get': function(){
+ 'get': function () {
assert.strictEqual(store.get(1).name, 'one');
assert.strictEqual(store.get(4).name, 'four');
assert.strictEqual(store.get(3).id, 3);
assert.strictEqual(store.getIdentity(store.get(2)), 2);
assert.isTrue(store.get(5).prime);
},
- 'query': function(){
+ 'query': function () {
assert.strictEqual(store.query({prime: true}).length, 3);
assert.strictEqual(store.query({even: true})[1].name, 'four');
},
- 'query with string': function(){
+ 'query with string': function () {
assert.strictEqual(store.query({name: 'two'}).length, 1);
assert.strictEqual(store.query({name: 'two'})[0].name, 'two');
},
- 'query with reg exp': function(){
+ 'query with reg exp': function () {
assert.strictEqual(store.query({name: /^t/}).length, 2);
assert.strictEqual(store.query({name: /^t/})[1].name, 'three');