Skip to content

Instantly share code, notes, and snippets.

View puzzfuzz's full-sized avatar

Chris Puzzo puzzfuzz

View GitHub Profile
// Rigging.js
class Rigging {
/* ... */
cartUpdated = (newCart) => {
this.dispatch(cartActions.cartUpdated(newCart));
};
}
// RiggingApp.js
class RiggingApp {
constructor({ componentClass, mountSites }) { /*...*/ }
setStore(store) {
// scope a reference of the store to pass to app instances
this.store = store;
}
init() { /* forEach mountsite: _initMountSite */ }
// CartController.jsx
@CartContainer
export default class CartController extends Component {
static propTypes = {
cart: PropTypes.object.isRequired,
adjustQuantity: PropTypes.func.isRequired
};
render() {
const { cart, adjustQuantity } = this.props;
const store = createStore(/* ... */);
// ...
ReactDOM.render(
<Provider store={store}>
<MyCompA />
</Provider>,
document.getElementById('mountsite-A')
);
/** src/reducers/cart.js **/
const initialState = {
...window.shopifyData.cart, // Rehydrate cart state from server data
isUpdating: false
};
const cart = (state = initialState, action) => { // Bootstrap initial state
switch (action.type) {
case 'CART_IS_UPDATING': {
<!-- snippets/_data-cart.liquid -->
<script type="text/javascript">
window.shopifyData = window.shopifyData || {};
window.shopifyData.cart = {{ cart | json }};
</script>
<!-- snippets/_data-product.liquid -->
<script type="text/javascript">
window.shopifyData = window.shopifyData || {};
window.shopifyData.currentProduct = {{ product | json }};
@puzzfuzz
puzzfuzz / .eslintrc
Created November 5, 2015 16:54
Minimal .eslintrc for working with ES6 and React
{
"env": {
"es6": true,
"browser": true
},
"ecmaFeatures": {
"modules": true,
"jsx": true
}
}