Skip to content

Instantly share code, notes, and snippets.

View gpbl's full-sized avatar

Giampaolo Bellavite gpbl

View GitHub Profile
@gpbl
gpbl / connectToStores.js
Last active August 29, 2015 14:18
Make a Component listen to fluxible stores
import React from "react";
import { FluxibleMixin } from "fluxible";
/**
* Make a Component listen to fluxible stores and pass the object returned by
* getState as props to Component.
*
* Heavily inspired by this article from @dan_abramov
* https://medium.com/@dan_abramov/mixins-are-dead-long-live-higher-order-components-94a0d2f9e750
*
@gpbl
gpbl / EventListenerMixin.js
Last active August 29, 2015 14:15
EventListenerMixin for fluxible
// Add a listenTo() method to listen to a specific store event (see comment for an example)
const EventListenerMixin = {
componentDidMount() {
this._storeEventListeners = [];
},
listenTo(store, eventName, handler) {
if (!handler) {
@gpbl
gpbl / StatusStore.js
Last active January 11, 2024 06:05
Fluxible Store for keeping track of loading and error states for any payload (usage example in comments)
import createStore from 'fluxible/utils/createStore';
import hashObject from 'hash-object';
import { omit } from 'lodash';
const debug = require('debug')('App:StatusStore');
const StatusStore = createStore({
storeName: 'StatusStore',
handlers: {
@gpbl
gpbl / reflux-master-detail.md
Last active November 3, 2015 13:19
Using Reflux stores and actions for a Master/Detail app with React

Reflux stores and actions in a Master/Detail app

Example and reasonings when using Reflux stores and actions for a Master/Detail app with React – with an eye to server-side rendering. Some concepts apply to reflux#166 and reflux#180.

Requirements

Must work with a router

This hypotetical app would use a router to display a list of items (e.g. at the url example.org/items, the master view) and a single item (e.g. example.org/items/:id, the detail view).