This file contains 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 characters
const ContactForm = ({ data, editData }) => ( | |
<div> | |
<h4>Contact Form</h4> | |
<input | |
type="text" | |
value={data.name} | |
onChange={e => editData({ name: e.target.value })} | |
/> | |
<input | |
type="text" |
This file contains 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 characters
const EDIT_CONTACT_FORM = "EDIT_CONTACT_FORM"; | |
const CLEAR_CONTACT_FORM = "CLEAR_CONTACT_FORM"; | |
const contactForm = (state = {}, action) => { | |
const { type, payload } = action; | |
switch (type) { | |
case EDIT_CONTACT_FORM: | |
return { | |
...state, | |
...payload |
This file contains 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 characters
#!/bin/bash | |
# install dependencies | |
sudo apt-get update | |
sudo apt-get install -y build-essential | |
sudo apt-get install -y cmake | |
sudo apt-get install -y libgtk2.0-dev | |
sudo apt-get install -y pkg-config | |
sudo apt-get install -y python-numpy python-dev | |
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev | |
sudo apt-get install -y libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev |
This file contains 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 characters
const messagePath = '/dummy'; | |
const messageActionCreator = (value) => ({ | |
type: 'SET_MESSAGE', | |
payload: value | |
}); | |
const messageSelector = (state) => state.dummy; | |
const linkMessage = linkStoreWithPath(messagePath, messageActionCreator, messageSelector) |
This file contains 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 characters
const linkStoreWithPath = (path, actionCreator, selector) => { | |
return (db, store) => { | |
let previous = selector(store.getState()); | |
let mustWrite = true; | |
const fromDb = (db, dispatch) => { | |
const listener = db.ref(path).on("value", snap => { | |
if (snap.val()) { | |
mustWrite = false; | |
dispatch(actionCreator(snap.val())); |
This file contains 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 characters
componentDidMount() { | |
const { store } = this.props.store; | |
this.unlink = linkStoreWithDb(fromDb, fromStore)( | |
firebase.database(), | |
store | |
); | |
} | |
componentWillUnmount() { | |
this.unlink(); |
This file contains 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 characters
const linkStoreWithDb = (fromDb, fromStore) => { | |
return (db, store) => { | |
const unlinkFromDb = fromDb && fromDb(db, store.dispatch); | |
const unlinkFromStore = fromStore && store.subscribe(() => fromStore(store.getState, db)); | |
const unlink = () => { | |
unlinkFromDb && unlinkFromDb(); | |
unlinkFromStore && unlinkFromStore(); | |
} | |
return unlink; |
This file contains 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 characters
let mustWrite = true; // Should we write the database? | |
const fromDb = (db, dispatch) => { | |
const listener = db.ref('/message').on('value', snap => { | |
if (snap.val()) { | |
mustWrite = false; // Don't write the next dispatch | |
dispatch({ type: 'SET_MESSAGE', payload: data.val()}); | |
mustWrite = true; // Done! Start writing again | |
} | |
}); |
This file contains 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 characters
const linkMessage = linkStoreWithDb(fromDb, fromStore) | |
linkMessage(firebase.database, store) |
This file contains 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 characters
const linkStoreWithDb = (fromDb, fromStore) => { | |
return (db, store) => { | |
fromDb(db, store.dispatch); | |
store.subscribe(() => fromStore(store.getState(), db) | |
} | |
} |