Last active
November 10, 2015 08:17
-
-
Save phaistonian/2542563e6e5d7e5a2f97 to your computer and use it in GitHub Desktop.
Revisions
-
phaistonian revised this gist
Aug 14, 2015 . No changes.There are no files selected for viewing
-
phaistonian created this gist
Aug 14, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ import Rebase from 're-base'; const endPoint = 'actions'; const firebaseUrl = 'https://firesync.firebaseio.com'; const client = String(Date.now() + Math.random() * 100); const data = []; let initiated = false; const base = Rebase.createClass(firebaseUrl); function firesync (store) { if (!initiated) { base.listenTo(endPoint, { context: {}, asArray: true, then(newData) { newData.filter(item => item.client !== client) .forEach(item => { store.dispatch({...item.data, client}); }); } }); initiated = true; } return next => action => { const value = next(action); if (!value.client) { base.post(endPoint, { data: [...data, { client, ts: Date.now(), data: value }] }); } return value; }; } export default firesync;