Skip to content

Commit

Permalink
Merge pull request #58 from storybooks/no-redux
Browse files Browse the repository at this point in the history
Remove Redux and use React Komposer only.
  • Loading branch information
arunoda authored Nov 12, 2016
2 parents ff037c1 + 3df5d55 commit 6e1db8a
Show file tree
Hide file tree
Showing 35 changed files with 4,202 additions and 181 deletions.
34 changes: 34 additions & 0 deletions dist/compose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.setActions = exports.setContext = undefined;

var _reactKomposer = require('react-komposer');

var _context = void 0,
_actions = void 0;

var setContext = exports.setContext = function setContext(c) {
_context = c;
};

var setActions = exports.setActions = function setActions(a) {
_actions = a;
};

var compose = (0, _reactKomposer.setDefaults)({
propsToWatch: [],
pure: true,
env: {
context: function context() {
return _context;
},
actions: function actions() {
return _actions;
}
}
});

exports.default = compose;
5 changes: 5 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ exports.default = function (domNode, provider) {
app.loadModule(_api2.default);
app.loadModule(_ui2.default);

(0, _compose.setContext)(context);
(0, _compose.setActions)(app.actions);

app.init();
};

Expand All @@ -57,6 +60,8 @@ var _ui = require('./modules/ui');

var _ui2 = _interopRequireDefault(_ui);

var _compose = require('./compose');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var Provider = exports.Provider = function () {
Expand Down
10 changes: 4 additions & 6 deletions dist/modules/api/configs/init_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ exports.default = function (provider, reduxStore, actions) {
(_actions$shortcuts = actions.shortcuts).setOptions.apply(_actions$shortcuts, arguments);
},
getQueryParam: function getQueryParam(key) {
var _reduxStore$getState = reduxStore.getState();

var api = _reduxStore$getState.api;
var _reduxStore$getState = reduxStore.getState(),
api = _reduxStore$getState.api;

if (api.customQueryParams) {
return api.customQueryParams[key];
Expand All @@ -53,9 +52,8 @@ exports.default = function (provider, reduxStore, actions) {

// subscribe to redux store and trigger onStory's callback
reduxStore.subscribe(function () {
var _reduxStore$getState2 = reduxStore.getState();

var api = _reduxStore$getState2.api;
var _reduxStore$getState2 = reduxStore.getState(),
api = _reduxStore$getState2.api;

if (!api) return;

Expand Down
13 changes: 6 additions & 7 deletions dist/modules/api/configs/reducers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exports.ensureStory = ensureStory;
exports.jumpToStory = jumpToStory;

exports.default = function () {
var state = arguments.length <= 0 || arguments[0] === undefined ? defaultState : arguments[0];
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState;
var action = arguments[1];

switch (action.type) {
Expand All @@ -38,10 +38,9 @@ exports.default = function () {

case _actions.types.JUMP_TO_STORY:
{
var _jumpToStory = jumpToStory(state.stories, state.selectedKind, state.selectedStory, action.direction);

var _selectedKind = _jumpToStory.selectedKind;
var _selectedStory = _jumpToStory.selectedStory;
var _jumpToStory = jumpToStory(state.stories, state.selectedKind, state.selectedStory, action.direction),
_selectedKind = _jumpToStory.selectedKind,
_selectedStory = _jumpToStory.selectedStory;

return (0, _extends3.default)({}, state, {
selectedKind: _selectedKind,
Expand Down Expand Up @@ -135,8 +134,8 @@ function jumpToStory(storyKinds, selectedKind, selectedStory, direction) {
var currentIndex = -1;

storyKinds.forEach(function (_ref) {
var kind = _ref.kind;
var stories = _ref.stories;
var kind = _ref.kind,
stories = _ref.stories;

stories.forEach(function (story) {
flatteredStories.push({ kind: kind, story: story });
Expand Down
4 changes: 2 additions & 2 deletions dist/modules/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ exports.default = {
reducers: _reducers2.default,
actions: _actions3.default,
load: function load(_ref, _actions) {
var reduxStore = _ref.reduxStore;
var provider = _ref.provider;
var reduxStore = _ref.reduxStore,
provider = _ref.provider;

(0, _init_api2.default)(provider, reduxStore, _actions);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/modules/shortcuts/configs/reducers/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var _extends3 = _interopRequireDefault(_extends2);
exports.keyEventToState = keyEventToState;

exports.default = function () {
var state = arguments.length <= 0 || arguments[0] === undefined ? defaultState : arguments[0];
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState;
var action = arguments[1];

switch (action.type) {
Expand Down
8 changes: 4 additions & 4 deletions dist/modules/ui/components/left_panel/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ var linkStyle = {
};

var Header = function Header(_ref) {
var openShortcutsHelp = _ref.openShortcutsHelp;
var name = _ref.name;
var url = _ref.url;
var openShortcutsHelp = _ref.openShortcutsHelp,
name = _ref.name,
url = _ref.url;
return _react2.default.createElement(
'div',
{ style: wrapperStyle },
_react2.default.createElement(
'button',
{ style: shortcutIconStyle, onClick: openShortcutsHelp },
''
'\u2318'
),
_react2.default.createElement(
'a',
Expand Down
10 changes: 5 additions & 5 deletions dist/modules/ui/components/left_panel/stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ var Stories = function (_React$Component) {
}, {
key: 'fireOnStory',
value: function fireOnStory(story) {
var _props = this.props;
var onSelectStory = _props.onSelectStory;
var selectedKind = _props.selectedKind;
var _props = this.props,
onSelectStory = _props.onSelectStory,
selectedKind = _props.selectedKind;

if (onSelectStory) onSelectStory(selectedKind, story);
}
Expand Down Expand Up @@ -118,8 +118,8 @@ var Stories = function (_React$Component) {
}, {
key: 'renderKind',
value: function renderKind(_ref2) {
var kind = _ref2.kind;
var stories = _ref2.stories;
var kind = _ref2.kind,
stories = _ref2.stories;
var selectedKind = this.props.selectedKind;

var style = (0, _extends3.default)({ display: 'block' }, kindStyle);
Expand Down
2 changes: 1 addition & 1 deletion dist/modules/ui/components/left_panel/text_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ var TextFilter = function (_React$Component) {
onClick: this.fireOnClear,
className: 'clear'
},
'×'
'\xD7'
)
);
}
Expand Down
8 changes: 4 additions & 4 deletions dist/modules/ui/components/shortcuts_help.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var Keys = exports.Keys = function Keys(_ref) {
arr.length - 1 !== index ? _react2.default.createElement(
'span',
null,
'/  '
'/ \xA0'
) : ''
);
});
Expand Down Expand Up @@ -131,9 +131,9 @@ Shortcuts.propTypes = {
};

var ShortcutsHelp = exports.ShortcutsHelp = function ShortcutsHelp(_ref3) {
var isOpen = _ref3.isOpen;
var onClose = _ref3.onClose;
var platform = _ref3.platform;
var isOpen = _ref3.isOpen,
onClose = _ref3.onClose,
platform = _ref3.platform;
return _react2.default.createElement(
_reactModal2.default,
{
Expand Down
47 changes: 23 additions & 24 deletions dist/modules/ui/configs/handle_routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,20 @@ function changeUrl(reduxStore) {
// Do not change the URL if we are inside a popState event.
if (config.insidePopState) return;

var _reduxStore$getState = reduxStore.getState();

var api = _reduxStore$getState.api;
var shortcuts = _reduxStore$getState.shortcuts;
var ui = _reduxStore$getState.ui;
var _reduxStore$getState = reduxStore.getState(),
api = _reduxStore$getState.api,
shortcuts = _reduxStore$getState.shortcuts,
ui = _reduxStore$getState.ui;

if (!api) return;

var selectedKind = api.selectedKind;
var selectedStory = api.selectedStory;
var customQueryParams = api.customQueryParams;
var full = shortcuts.goFullScreen;
var down = shortcuts.showDownPanel;
var left = shortcuts.showLeftPanel;
var panelRight = shortcuts.downPanelInRight;
var selectedKind = api.selectedKind,
selectedStory = api.selectedStory,
customQueryParams = api.customQueryParams;
var full = shortcuts.goFullScreen,
down = shortcuts.showDownPanel,
left = shortcuts.showLeftPanel,
panelRight = shortcuts.downPanelInRight;
var downPanel = ui.selectedDownPanel;


Expand Down Expand Up @@ -93,18 +92,18 @@ function changeUrl(reduxStore) {
}

function updateStore(queryParams, actions) {
var selectedKind = queryParams.selectedKind;
var selectedStory = queryParams.selectedStory;
var _queryParams$full = queryParams.full;
var full = _queryParams$full === undefined ? 0 : _queryParams$full;
var _queryParams$down = queryParams.down;
var down = _queryParams$down === undefined ? 1 : _queryParams$down;
var _queryParams$left = queryParams.left;
var left = _queryParams$left === undefined ? 1 : _queryParams$left;
var _queryParams$panelRig = queryParams.panelRight;
var panelRight = _queryParams$panelRig === undefined ? 0 : _queryParams$panelRig;
var downPanel = queryParams.downPanel;
var customQueryParams = (0, _objectWithoutProperties3.default)(queryParams, ['selectedKind', 'selectedStory', 'full', 'down', 'left', 'panelRight', 'downPanel']);
var selectedKind = queryParams.selectedKind,
selectedStory = queryParams.selectedStory,
_queryParams$full = queryParams.full,
full = _queryParams$full === undefined ? 0 : _queryParams$full,
_queryParams$down = queryParams.down,
down = _queryParams$down === undefined ? 1 : _queryParams$down,
_queryParams$left = queryParams.left,
left = _queryParams$left === undefined ? 1 : _queryParams$left,
_queryParams$panelRig = queryParams.panelRight,
panelRight = _queryParams$panelRig === undefined ? 0 : _queryParams$panelRig,
downPanel = queryParams.downPanel,
customQueryParams = (0, _objectWithoutProperties3.default)(queryParams, ['selectedKind', 'selectedStory', 'full', 'down', 'left', 'panelRight', 'downPanel']);


if (selectedKind && selectedStory) {
Expand Down
2 changes: 1 addition & 1 deletion dist/modules/ui/configs/reducers/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);

exports.default = function () {
var state = arguments.length <= 0 || arguments[0] === undefined ? defaultState : arguments[0];
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState;
var action = arguments[1];

switch (action.type) {
Expand Down
18 changes: 10 additions & 8 deletions dist/modules/ui/containers/down_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.composer = composer;
exports.mapper = mapper;

var _down_panel = require('../components/down_panel');

var _down_panel2 = _interopRequireDefault(_down_panel);

var _mantraCore = require('mantra-core');
var _gen_redux_loader = require('../libs/gen_redux_loader');

var _redux_composer = require('../libs/redux_composer');
var _gen_redux_loader2 = _interopRequireDefault(_gen_redux_loader);

var _redux_composer2 = _interopRequireDefault(_redux_composer);
var _compose = require('../../../compose');

var _compose2 = _interopRequireDefault(_compose);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function composer(_ref, _ref2) {
function mapper(_ref, props, _ref2) {
var ui = _ref.ui;
var context = _ref2.context;
var actions = _ref2.actions;
var context = _ref2.context,
actions = _ref2.actions;

var panels = context().provider.getPanels();
var actionMap = actions();
Expand All @@ -33,4 +35,4 @@ function composer(_ref, _ref2) {
};
}

exports.default = (0, _mantraCore.composeAll)((0, _redux_composer2.default)(composer), (0, _mantraCore.useDeps)())(_down_panel2.default);
exports.default = (0, _compose2.default)((0, _gen_redux_loader2.default)(mapper))(_down_panel2.default);
20 changes: 11 additions & 9 deletions dist/modules/ui/containers/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.composer = undefined;
exports.mapper = undefined;

var _lodash = require('lodash.pick');

var _lodash2 = _interopRequireDefault(_lodash);

var _layout = require('../components/layout');

var _layout2 = _interopRequireDefault(_layout);

var _mantraCore = require('mantra-core');
var _gen_redux_loader = require('../libs/gen_redux_loader');

var _lodash = require('lodash.pick');

var _lodash2 = _interopRequireDefault(_lodash);
var _gen_redux_loader2 = _interopRequireDefault(_gen_redux_loader);

var _redux_composer = require('../libs/redux_composer');
var _compose = require('../../../compose');

var _redux_composer2 = _interopRequireDefault(_redux_composer);
var _compose2 = _interopRequireDefault(_compose);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var composer = exports.composer = function composer(_ref) {
var mapper = exports.mapper = function mapper(_ref) {
var shortcuts = _ref.shortcuts;

return (0, _lodash2.default)(shortcuts, 'showLeftPanel', 'showDownPanel', 'goFullScreen', 'downPanelInRight');
};

exports.default = (0, _mantraCore.composeAll)((0, _redux_composer2.default)(composer), (0, _mantraCore.useDeps)())(_layout2.default);
exports.default = (0, _compose2.default)((0, _gen_redux_loader2.default)(mapper))(_layout2.default);
Loading

0 comments on commit 6e1db8a

Please sign in to comment.