Skip to content

Commit

Permalink
Allow custom dispatcher to be specified
Browse files Browse the repository at this point in the history
- Alt constructor takes config object that enables user to override
  defaults, in this case the dispatcher
- If dispatcher has interface with waitFor, dispatchToken, register, and
  dispatch functions, then it is valid and can be used, otherwise the
  default FB dispatcher is used as fallback
  • Loading branch information
jdlehman committed Mar 29, 2015
1 parent 2af3c13 commit 8f57b6c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 19 deletions.
15 changes: 4 additions & 11 deletions dist/alt-browser-with-addons.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Alt = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
"use strict";

/**
* This mixin lets you setup your listeners. It is similar to Fluxible's mixin.
*
Expand Down Expand Up @@ -80,7 +79,6 @@ module.exports = FluxyMixin;

},{"./Subscribe":4}],2:[function(require,module,exports){
"use strict";

var Subscribe = require("./Subscribe");

var ListenerMixin = {
Expand Down Expand Up @@ -111,7 +109,6 @@ module.exports = ListenerMixin;

},{"./Subscribe":4}],3:[function(require,module,exports){
"use strict";

/**
* This mixin automatically sets the state for you based on the key you provide
*
Expand Down Expand Up @@ -193,7 +190,6 @@ module.exports = ReactStateMagicMixin;

},{"./Subscribe":4}],4:[function(require,module,exports){
"use strict";

var Symbol = require("es-symbol");
var MIXIN_REGISTRY = Symbol("alt store listeners");

Expand Down Expand Up @@ -1355,9 +1351,11 @@ var createStoreFromObject = function (alt, StoreModel, key, saveStore) {

var Alt = (function () {
function Alt() {
var config = arguments[0] === undefined ? {} : arguments[0];

_classCallCheck(this, Alt);

this.dispatcher = new Dispatcher();
this.dispatcher = config.dispatcher || new Dispatcher();
this.actions = {};
this.stores = {};
this[LAST_SNAPSHOT] = this[INIT_SNAPSHOT] = "{}";
Expand Down Expand Up @@ -1449,9 +1447,7 @@ var Alt = (function () {
}

return this.createActions(function () {
var _ref;

(_ref = this).generateActions.apply(_ref, actionNames);
this.generateActions.apply(this, actionNames);
});
}
},
Expand Down Expand Up @@ -1612,7 +1608,6 @@ module.exports = Alt;

},{"es-symbol":5,"eventemitter3":6,"flux":7,"object-assign":10}],13:[function(require,module,exports){
"use strict";

/**
* ActionListeners(alt: AltInstance): ActionListenersInstance
*
Expand Down Expand Up @@ -1675,7 +1670,6 @@ ActionListeners.prototype.removeAllActionListeners = function () {

},{"es-symbol":5}],14:[function(require,module,exports){
"use strict";

/**
* DispatcherRecorder(alt: AltInstance): DispatcherInstance
*
Expand Down Expand Up @@ -1811,7 +1805,6 @@ DispatcherRecorder.prototype.loadEvents = function (events) {

},{"es-symbol":5}],15:[function(require,module,exports){
"use strict";

/**
* makeFinalStore(alt: AltInstance): AltStore
*
Expand Down
8 changes: 4 additions & 4 deletions dist/alt-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1099,9 +1099,11 @@ var createStoreFromObject = function (alt, StoreModel, key, saveStore) {

var Alt = (function () {
function Alt() {
var config = arguments[0] === undefined ? {} : arguments[0];

_classCallCheck(this, Alt);

this.dispatcher = new Dispatcher();
this.dispatcher = config.dispatcher || new Dispatcher();
this.actions = {};
this.stores = {};
this[LAST_SNAPSHOT] = this[INIT_SNAPSHOT] = "{}";
Expand Down Expand Up @@ -1193,9 +1195,7 @@ var Alt = (function () {
}

return this.createActions(function () {
var _ref;

(_ref = this).generateActions.apply(_ref, actionNames);
this.generateActions.apply(this, actionNames);
});
}
},
Expand Down
3 changes: 2 additions & 1 deletion dist/alt-with-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,10 @@ var createStoreFromObject = function (alt, StoreModel, key, saveStore) {

var Alt = (function () {
function Alt() {
var config = arguments[0] === undefined ? {} : arguments[0];
babelHelpers.classCallCheck(this, Alt);

this.dispatcher = new Dispatcher();
this.dispatcher = config.dispatcher || new Dispatcher();
this.actions = {};
this.stores = {};
this[LAST_SNAPSHOT] = this[INIT_SNAPSHOT] = "{}";
Expand Down
4 changes: 3 additions & 1 deletion dist/alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,11 @@ var createStoreFromObject = function (alt, StoreModel, key, saveStore) {

var Alt = (function () {
function Alt() {
var config = arguments[0] === undefined ? {} : arguments[0];

_classCallCheck(this, Alt);

this.dispatcher = new Dispatcher();
this.dispatcher = config.dispatcher || new Dispatcher();
this.actions = {};
this.stores = {};
this[LAST_SNAPSHOT] = this[INIT_SNAPSHOT] = "{}";
Expand Down
4 changes: 2 additions & 2 deletions src/alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ const createStoreFromObject = (alt, StoreModel, key, saveStore) => {
}

class Alt {
constructor() {
this.dispatcher = new Dispatcher()
constructor(config = {}) {
this.dispatcher = config.dispatcher || new Dispatcher()
this.actions = {}
this.stores = {}
this[LAST_SNAPSHOT] = this[INIT_SNAPSHOT] = '{}'
Expand Down
23 changes: 23 additions & 0 deletions test/alt-config-object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { assert } from 'chai'
import Alt from '../dist/alt-with-runtime'

class CustomDispatcher {
waitFor() {}
dispatchToken() {}
register() {}
dispatch() {}
extraMethod() {}
}

export default {
'custom dispatcher can be specified in alt config'() {
const alt = new Alt({
dispatcher: new CustomDispatcher()
})
const dispatcher = alt.dispatcher

// uses custom dispatcher
assert.equal(typeof dispatcher.extraMethod, 'function')
assert.equal(typeof dispatcher.dispatch, 'function')
}
}

0 comments on commit 8f57b6c

Please sign in to comment.