Skip to content

Instantly share code, notes, and snippets.

@colinf
colinf / sbf_StoreTemplate.js
Last active July 13, 2016 16:09
Standard Flux Store definition in ES5 ( See http://bit.ly/29RY6gq )
var AppDispatcher = require('../dispatcher/AppDispatcher');
var AppConstants = require('../constants/AppConstants');
var EventEmitter = require('events').EventEmitter;
var assign = require('object-assign');
var ActionTypes = AppConstants.ActionTypes;
var CHANGE_EVENT = 'change';
var ExampleStore = assign({}, EventEmitter.prototype, {
@colinf
colinf / sbf_Store.js
Last active July 13, 2016 16:09
Base Flux Store class in ES6 ( See http://bit.ly/29RY6gq )
import EventEmitter from 'events';
var CHANGE_EVENT = 'change';
class Store extends EventEmitter {
constructor() {
super();
}
@colinf
colinf / sbf_AppStore.js
Last active July 13, 2016 16:09
Flux Store class in ES6 ( See http://bit.ly/29RY6gq )
import FluxStore from './FluxStore';
import AppDispatcher from '../dispatcher/AppDispatcher';
import {ActionTypes} from '../constants/AppConstants';
let appState;
function reset() {
appState = {};
}
@colinf
colinf / ajh_babelSnippet.js
Last active July 13, 2016 16:07
Example of code generated by babel ( see http://bit.ly/29x17B8 )
Object.defineProperty(exports, '__esModule', { value: true });
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) {
var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if
('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype,
protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2,
receiver = _x3; desc = parent = getter = undefined; _again = false; var desc = Object.getOwnPropertyDescriptor(object,
@colinf
colinf / onn_rawData.clj
Last active July 13, 2016 15:57
The flux-chat data ( see http://bit.ly/29EyV1D )
(def raw-data [
{
:id "m_1"
:threadID "t_1"
:threadName "Jing and Bill"
:authorName "Bill"
:text "Hey Jing want to give a Flux talk at ForwardJS?"
:timestamp (- (dt/now) 99999)}
{
:id "m_2"
@colinf
colinf / onn_Reconciler.clj
Last active July 13, 2016 15:57
Defining the reconciler and adding a dom root for it to control ( see http://bit.ly/29EyV1D )
(def reconciler
(om/reconciler {:state {:threads (reduce threads [] raw-data)}
:parser (om/parser {:read read})}))
(om/add-root! reconciler
ChatApp
(gdom/getElement "app"))
@colinf
colinf / onn_DataIn.clj
Last active July 13, 2016 15:56
The data added to the reconciler ( see http://bit.ly/29EyV1D )
{:threads
[{:thread/id "t_1",
:thread/name "Jing and Bill",
:thread/messages
[{:message/id "m_1",
:message/author-name "Bill",
:message/text "Hey Jing want to give a Flux talk at ForwardJS?",
:message/date #inst "2015-11-24T12:59:52.245-00:00"}
{:message/id "m_2",
:message/author-name "Bill",
@colinf
colinf / onn_DataOut.clj
Last active July 13, 2016 15:54
The data retrieved from the Om Next reconciler ( see http://bit.ly/29EyV1D )
{:threads
[[:threads/by-id "t_1"]
[:threads/by-id "t_2"]
[:threads/by-id "t_3"]],
:messages/by-id
{"m_1"
{:message/id "m_1",
:message/author-name "Bill",
:message/text "Hey Jing want to give a Flux talk at ForwardJS?",
:message/date #inst "2015-11-24T15:48:21.793-00:00"},
@colinf
colinf / oda_message_item.clj
Last active July 13, 2016 16:03
The query statements from message_item.clj ( see http://bit.ly/29ywoTL )
(defui MessageItem
static om/Ident
(ident [this {:keys [message/id]}]
[:messages/by-id id])
static om/IQuery
(query [this]
[:message/id :message/author-name :message/date :message/text])
Object
@colinf
colinf / oda_DataOut.clj
Last active July 13, 2016 16:03
om/Ident influence on the data retrieved from the Om Next reconciler ( see http://bit.ly/29ywoTL )
{:threads
[[:threads/by-id "t_1"]
[:threads/by-id "t_2"]
[:threads/by-id "t_3"]],
:messages/bucket
{"m_1"
{:message/id "m_1",
:message/author-name "Bill",
:message/text "Hey Jing want to give a Flux talk at ForwardJS?",
:message/date #inst "2015-12-08T14:48:34.292-00:00"},