lore-actions
Advanced tools
Comparing version 0.11.0 to 0.12.0-beta.1
@@ -11,3 +11,3 @@ 'use strict'; | ||
/* | ||
* Blueprint for FetchAll method | ||
* Blueprint for Find method | ||
*/ | ||
@@ -49,2 +49,10 @@ | ||
if (options.onSuccess) { | ||
var actions = []; | ||
if (options.normalize && options.normalize.getActions) { | ||
// look through all models in the collection and generate actions for any attributes | ||
// with nested data that should be normalized | ||
actions = options.normalize.getActions(collection); | ||
} | ||
dispatch({ | ||
@@ -55,2 +63,7 @@ type: options.onSuccess.actionType, | ||
}); | ||
if (options.normalize && options.normalize.dispatchActions) { | ||
// dispatch any actions created from normalizing nested data | ||
options.normalize.dispatchActions(actions, dispatch); | ||
} | ||
} | ||
@@ -57,0 +70,0 @@ }).catch(function (response) { |
@@ -11,3 +11,3 @@ 'use strict'; | ||
/* | ||
* Blueprint for Fetch method | ||
* Blueprint for Get method | ||
*/ | ||
@@ -33,2 +33,4 @@ | ||
return function fetch(modelId) { | ||
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return function (dispatch) { | ||
@@ -39,4 +41,14 @@ var model = new Model({ | ||
model.fetch().then(function () { | ||
model.fetch({ | ||
data: query | ||
}).then(function () { | ||
if (options.onSuccess) { | ||
var actions = []; | ||
if (options.normalize && options.normalize.getActions) { | ||
// look through the model and generate actions for any attributes with | ||
// nested data that should be normalized | ||
actions = options.normalize.getActions(model); | ||
} | ||
dispatch({ | ||
@@ -46,2 +58,7 @@ type: options.onSuccess.actionType, | ||
}); | ||
if (options.normalize && options.normalize.dispatchActions) { | ||
// dispatch any actions created from normalizing nested data | ||
options.normalize.dispatchActions(actions, dispatch); | ||
} | ||
} | ||
@@ -48,0 +65,0 @@ }).catch(function (response) { |
{ | ||
"name": "lore-actions", | ||
"version": "0.11.0", | ||
"version": "0.12.0-beta.1", | ||
"license": "MIT", | ||
@@ -28,3 +28,3 @@ "description": "Blueprints to reduce boilerplate for Redux actions", | ||
"chai": "^3.4.1", | ||
"lore-models": "^0.11.0", | ||
"lore-models": "^0.12.0-beta.1", | ||
"mocha": "^2.3.4", | ||
@@ -31,0 +31,0 @@ "nock": "^3.3.2", |
@@ -5,3 +5,3 @@ const _ = require('lodash'); | ||
/* | ||
* Blueprint for FetchAll method | ||
* Blueprint for Find method | ||
*/ | ||
@@ -38,2 +38,10 @@ | ||
if (options.onSuccess) { | ||
var actions = []; | ||
if (options.normalize && options.normalize.getActions) { | ||
// look through all models in the collection and generate actions for any attributes | ||
// with nested data that should be normalized | ||
actions = options.normalize.getActions(collection); | ||
} | ||
dispatch({ | ||
@@ -44,2 +52,7 @@ type: options.onSuccess.actionType, | ||
}); | ||
if (options.normalize && options.normalize.dispatchActions) { | ||
// dispatch any actions created from normalizing nested data | ||
options.normalize.dispatchActions(actions, dispatch); | ||
} | ||
} | ||
@@ -46,0 +59,0 @@ }).catch(function(response) { |
@@ -5,3 +5,3 @@ const _ = require('lodash'); | ||
/* | ||
* Blueprint for Fetch method | ||
* Blueprint for Get method | ||
*/ | ||
@@ -22,3 +22,3 @@ module.exports = function(opts = {}) { | ||
return function fetch(modelId) { | ||
return function fetch(modelId, query = {}) { | ||
return function(dispatch) { | ||
@@ -29,4 +29,14 @@ const model = new Model({ | ||
model.fetch().then(function() { | ||
model.fetch({ | ||
data: query | ||
}).then(function() { | ||
if (options.onSuccess) { | ||
var actions = []; | ||
if (options.normalize && options.normalize.getActions) { | ||
// look through the model and generate actions for any attributes with | ||
// nested data that should be normalized | ||
actions = options.normalize.getActions(model); | ||
} | ||
dispatch({ | ||
@@ -36,2 +46,7 @@ type: options.onSuccess.actionType, | ||
}); | ||
if (options.normalize && options.normalize.dispatchActions) { | ||
// dispatch any actions created from normalizing nested data | ||
options.normalize.dispatchActions(actions, dispatch); | ||
} | ||
} | ||
@@ -38,0 +53,0 @@ }).catch(function(response) { |
53988
1686