cape-firebase
Advanced tools
Comparing version 0.3.1 to 0.4.0
@@ -29,2 +29,3 @@ 'use strict'; | ||
exports.handleTriplePut = handleTriplePut; | ||
exports.handleEntityUpdate = handleEntityUpdate; | ||
@@ -97,2 +98,10 @@ var _capeLodash = require('cape-lodash'); | ||
return (0, _util.triplePut)(firebase, action); | ||
} | ||
function handleEntityUpdate(_ref6) { | ||
var firebase = _ref6.firebase, | ||
action = _ref6.action, | ||
next = _ref6.next; | ||
next(action); | ||
return (0, _util.entityUpdate)(firebase, action.payload); | ||
} |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.uploadFile = exports.UPLOAD_FILE = exports.saveTriple = exports.SAVE_TRIPLE = exports.saveEntity = exports.SAVE_ENTITY = exports.logout = exports.LOGOUT = exports.auth = exports.AUTH = undefined; | ||
exports.uploadFile = exports.UPLOAD_FILE = exports.saveTriple = exports.SAVE_TRIPLE = exports.updateEntity = exports.UPDATE_ENTITY = exports.saveEntity = exports.SAVE_ENTITY = exports.logout = exports.LOGOUT = exports.auth = exports.AUTH = undefined; | ||
@@ -30,2 +30,5 @@ var _nthArg2 = require('lodash/nthArg'); | ||
var UPDATE_ENTITY = exports.UPDATE_ENTITY = 'fire/UPDATE_ENTITY'; | ||
var updateEntity = exports.updateEntity = (0, _capeRedux.createSimpleAction)(UPDATE_ENTITY, _identity3.default, (0, _nthArg3.default)(1)); | ||
var SAVE_TRIPLE = exports.SAVE_TRIPLE = 'fire/SAVE_TRIPLE'; | ||
@@ -32,0 +35,0 @@ var saveTriple = exports.saveTriple = (0, _capeRedux.createSimpleAction)(SAVE_TRIPLE, _identity3.default, (0, _nthArg3.default)(1)); |
@@ -30,3 +30,3 @@ 'use strict'; | ||
var dispatcher = exports.dispatcher = (_dispatcher = {}, _defineProperty(_dispatcher, _actions.AUTH, _actionHandlers.handleAuth), _defineProperty(_dispatcher, _actions.LOGOUT, _actionHandlers.handleLogout), _defineProperty(_dispatcher, _actions.SAVE_ENTITY, _actionHandlers.handleEntityPut), _defineProperty(_dispatcher, _actions.SAVE_TRIPLE, _actionHandlers.handleTriplePut), _defineProperty(_dispatcher, _reduxField.SUBMIT, _actionHandlers.handleFieldSubmit), _dispatcher); | ||
var dispatcher = exports.dispatcher = (_dispatcher = {}, _defineProperty(_dispatcher, _actions.AUTH, _actionHandlers.handleAuth), _defineProperty(_dispatcher, _actions.LOGOUT, _actionHandlers.handleLogout), _defineProperty(_dispatcher, _actions.SAVE_ENTITY, _actionHandlers.handleEntityPut), _defineProperty(_dispatcher, _actions.SAVE_TRIPLE, _actionHandlers.handleTriplePut), _defineProperty(_dispatcher, _reduxField.SUBMIT, _actionHandlers.handleFieldSubmit), _defineProperty(_dispatcher, _actions.UPDATE_ENTITY, _actionHandlers.handleEntityUpdate), _dispatcher); | ||
@@ -33,0 +33,0 @@ function fireMiddleware(firebase, entities) { |
@@ -40,8 +40,8 @@ 'use strict'; | ||
exports.entityPath = entityPath; | ||
exports.getValue = getValue; | ||
exports.getDbEntity = getDbEntity; | ||
exports.nextAction = nextAction; | ||
exports.entitySet = entitySet; | ||
exports.entityUpdate = entityUpdate; | ||
exports.triplePut = triplePut; | ||
exports.getValue = getValue; | ||
exports.getDbEntity = getDbEntity; | ||
exports.nextAction = nextAction; | ||
exports.arrayTrueObj = arrayTrueObj; | ||
@@ -81,6 +81,30 @@ | ||
} | ||
function entitySet(_ref, node) { | ||
var entity = _ref.entity, | ||
TIMESTAMP = _ref.TIMESTAMP; | ||
function getValue(method, db, id) { | ||
return db.child(id)[method]('value').then(function (res) { | ||
return res.val(); | ||
}); | ||
} | ||
var getChild = exports.getChild = (0, _partial3.default)(getValue, 'once'); | ||
function getDbEntity(firebase, entity) { | ||
return getChild(firebase.entity.child(entity.type), entity.id); | ||
} | ||
var onChild = exports.onChild = (0, _curry3.default)(function (actionType, db, id, callback) { | ||
return db.child(id).on(actionType, function (res) { | ||
return callback(res.val(), res.key); | ||
}); | ||
}); | ||
var getWatchChild = exports.getWatchChild = onChild('value'); | ||
var onChildChanged = exports.onChildChanged = onChild('child_changed'); | ||
function nextAction(_ref) { | ||
var action = _ref.action, | ||
next = _ref.next; | ||
return next(action); | ||
} | ||
function entitySet(firebase, node) { | ||
var entity = firebase.entity, | ||
TIMESTAMP = firebase.TIMESTAMP; | ||
var item = (0, _reduxGraph.insertFields)(node); | ||
@@ -90,21 +114,21 @@ item.dateCreated = TIMESTAMP; | ||
return entityDb(entity, item).set(item).then(function () { | ||
return item; | ||
return getDbEntity(firebase, item); | ||
}); | ||
} | ||
function entityUpdate(_ref2, node) { | ||
var entity = _ref2.entity, | ||
TIMESTAMP = _ref2.TIMESTAMP; | ||
function entityUpdate(firebase, node) { | ||
var entity = firebase.entity, | ||
TIMESTAMP = firebase.TIMESTAMP; | ||
var item = _extends({}, node, { dateModified: TIMESTAMP }); | ||
return entityDb(entity, item).update(item).then(function () { | ||
return item; | ||
return getDbEntity(firebase, item); | ||
}); | ||
} | ||
function triplePut(_ref3, _ref4) { | ||
function triplePut(_ref2, _ref3) { | ||
var _updateObj; | ||
var entity = _ref3.entity, | ||
TIMESTAMP = _ref3.TIMESTAMP; | ||
var payload = _ref4.payload, | ||
meta = _ref4.meta; | ||
var entity = _ref2.entity, | ||
TIMESTAMP = _ref2.TIMESTAMP; | ||
var payload = _ref3.payload, | ||
meta = _ref3.meta; | ||
@@ -127,24 +151,3 @@ var triple = (0, _reduxGraph.buildTriple)(payload); | ||
} | ||
function getValue(method, db, id) { | ||
return db.child(id)[method]('value').then(function (res) { | ||
return res.val(); | ||
}); | ||
} | ||
var getChild = exports.getChild = (0, _partial3.default)(getValue, 'once'); | ||
function getDbEntity(firebase, entity) { | ||
return getChild(firebase.entity.child(entity.type), entity.id); | ||
} | ||
var onChild = exports.onChild = (0, _curry3.default)(function (actionType, db, id, callback) { | ||
return db.child(id).on(actionType, function (res) { | ||
return callback(res.val(), res.key); | ||
}); | ||
}); | ||
var getWatchChild = exports.getWatchChild = onChild('value'); | ||
var onChildChanged = exports.onChildChanged = onChild('child_changed'); | ||
function nextAction(_ref5) { | ||
var action = _ref5.action, | ||
next = _ref5.next; | ||
return next(action); | ||
} | ||
function arrayTrueObj(arr) { | ||
@@ -151,0 +154,0 @@ if (!arr || !arr.length) return {}; |
{ | ||
"name": "cape-firebase", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "Help integrate CAPE redux projects with Firebase.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index", |
116728
447