flux-crud-store
Advanced tools
Comparing version 0.0.1 to 0.0.3
'use strict'; | ||
var assign = require('object-assign'); | ||
var extend = require('backbone').Collection.extend; | ||
@@ -21,3 +20,3 @@ var _ = require('underscore'); | ||
assign(CrudStoreActions.prototype, { | ||
_(CrudStoreActions.prototype).extend({ | ||
create: function (data) { | ||
@@ -55,7 +54,11 @@ var model = new this._collection.model(data); | ||
fetchAll: function () { | ||
this._fetchingAll = true; | ||
if (!this._collection.url) { | ||
throw 'fetchAll action requires \'url\' to be set on collection class!'; | ||
} | ||
this._isFetchingAll = true; | ||
this._collection.fetch({ | ||
silent: true, | ||
success: function () { | ||
this._fetchingAll = false; | ||
this._isFetchingAll = false; | ||
}.bind(this) | ||
@@ -65,2 +68,21 @@ }); | ||
fetch: function (id) { | ||
if (!this._collection.url) { | ||
throw 'fetch action requires \'url\' to be set on collection class!'; | ||
} | ||
var model = this._collection.get(id); | ||
if (!model) { | ||
model = new this._collection.model({ id: id }); | ||
this._collection.add(model); | ||
} | ||
this._isFetching[id] = true; | ||
model.fetch({ | ||
success: function () { | ||
this._isFetching[id] = false; | ||
}.bind(this) | ||
}); | ||
}, | ||
save: function (id) { | ||
@@ -67,0 +89,0 @@ var model = this._collection.get(id); |
@@ -5,3 +5,2 @@ 'use strict'; | ||
var OrderedMap = require('immutable').OrderedMap; | ||
var assign = require('object-assign'); | ||
var extend = Collection.extend; | ||
@@ -16,4 +15,7 @@ var _ = require('underscore'); | ||
CrudStore.extend = extend; | ||
CrudStore.instance = function () { | ||
return new this(); | ||
}; | ||
assign(CrudStore.prototype, { | ||
_(CrudStore.prototype).extend({ | ||
collection: Collection, | ||
@@ -26,4 +28,10 @@ | ||
if (!this.collection) { | ||
throw 'collection must be set on the Store class'; | ||
} | ||
this._collection = new this.collection(); | ||
this._viewModels = new OrderedMap(); | ||
this._isFetchingAll = false; | ||
this._isFetching = {}; | ||
}, | ||
@@ -48,3 +56,3 @@ | ||
getAll: function () { | ||
if (this._fetchingAll) { | ||
if (this._isFetchingAll) { | ||
return this._loadingResponse; | ||
@@ -67,2 +75,6 @@ } | ||
get: function (id) { | ||
if (this._isFetching[id]) { | ||
return this._loadingResponse; | ||
} | ||
var model = this._collection.get(id); | ||
@@ -69,0 +81,0 @@ |
@@ -6,3 +6,3 @@ { | ||
"author": "Holman Gao <holman@golmansax.com>", | ||
"version": "0.0.1", | ||
"version": "0.0.3", | ||
"main": "lib/index.js", | ||
@@ -23,2 +23,3 @@ "repository": { | ||
"devDependencies": { | ||
"browserify": "latest", | ||
"chai": "1.9.2", | ||
@@ -38,3 +39,2 @@ "dirty-chai": "latest", | ||
"immutable": "latest", | ||
"object-assign": "latest", | ||
"underscore": "latest" | ||
@@ -41,0 +41,0 @@ }, |
@@ -11,5 +11,18 @@ # Flux CRUD Store | ||
## Installation | ||
### Node | ||
```bash | ||
# Node | ||
npm install flux-crud-store --save | ||
``` | ||
```js | ||
var CrudStore = require('flux-crud-store').Store; | ||
var CrudActions = require('flux-crud-store').Actions; | ||
``` | ||
### Bower | ||
```bash | ||
bower install flux-crud-store | ||
``` | ||
```js | ||
// Assuming dist/flux_crud_store.js has been included without CommonJS or RequireJS | ||
var CrudStore = FluxCrudStore.Store; | ||
var CrudActions = FluxCrudStore.Actions; | ||
``` |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
3
28
8938
11
11
206
1
- Removedobject-assign@latest
- Removedobject-assign@4.1.1(transitive)