use the manager UI directly from the storybook-ui

This commit is contained in:
Arunoda Susiripala 2016-06-15 13:45:57 +05:30
parent 95fa4fd63e
commit a715750dfd
9 changed files with 3 additions and 305 deletions

53
dist/manager.js vendored

File diff suppressed because one or more lines are too long

1
dist/manager.js.map vendored
View File

@ -1 +0,0 @@
{"version":3,"file":"manager.js","sources":["webpack:///manager.js","webpack:///"],"mappings":"AAAA;ACssIA;;;;;;;;;;;;;;AAi4FA;;;;;;;;;;;AAwwGA;AA41IA;;;;;;;;;AAgyBA;AAyzEA;AAmrGA;AA0mHA;AAwnEA;;;;;AAsxCA;;;AAm4BA;AAuuHA;AA+8HA;AA2lHA","sourceRoot":""}

View File

@ -35,11 +35,9 @@
"es6-shim": "^0.35.1",
"express": "^4.13.3",
"json-stringify-safe": "^5.0.1",
"keycode": "^2.1.1",
"page-bus": "^3.0.1",
"qs": "^6.1.0",
"redbox-react": "^1.2.2",
"redux": "^3.5.2",
"shelljs": "^0.6.0",
"stack-source-map": "^1.0.5",
"uuid": "^2.0.1",
@ -58,7 +56,6 @@
"react": "^15.0.0",
"react-dom": "^15.0.0",
"lodash.pick": "^4.2.0",
"mantra-core": "^1.6.1",
"deep-equal": "^1.0.1",
"babel-cli": "^6.3.14",
"babel-eslint": "^6.0.2",

View File

@ -1,30 +0,0 @@
import 'es6-shim';
import { createStore, combineReducers } from 'redux';
import { createApp } from 'mantra-core';
import buildContext from './configs/context.js';
import apiModule from '@kadira/storybook-core/dist/modules/api';
import shortcutsModule from '@kadira/storybook-core/dist/modules/shortcuts';
import uiModule from '@kadira/storybook-core/dist/modules/ui';
import previewModule from './modules/preview';
export default function(domNode, provider) {
const reducer = combineReducers({
...apiModule.reducers,
...shortcutsModule.reducers,
...previewModule.reducers,
...uiModule.reducers,
});
const reduxStore = createStore(reducer);
const context = buildContext(reduxStore, domNode, provider);
const app = createApp(context);
app.loadModule(apiModule);
app.loadModule(shortcutsModule);
app.loadModule(previewModule);
app.loadModule(uiModule);
app.init();
}

View File

@ -1,7 +0,0 @@
export default function (reduxStore, domNode, provider) {
return {
reduxStore,
domNode,
provider,
};
}

View File

@ -1,5 +1,6 @@
var initManagerUI = require('./api.js');
import 'es6-shim';
var renderManagerUI = require('@kadira/storybook-core');
var Provider = require('./provider');
var rootEl = document.getElementById('root');
initManagerUI.default(rootEl, new (Provider.default)());
renderManagerUI.default(rootEl, new (Provider.default)());

View File

@ -1,178 +0,0 @@
import initPageBus from '../init_pagebus';
import { expect } from 'chai';
const { describe, it } = global;
import sinon from 'sinon';
import { EventEmitter } from 'events';
describe('manager.preview.config.initPageBus', () => {
it('should send currentStory to the iframe', (done) => {
const dataId = 'dasds';
const kind = 'fdfd';
const story = 'dfdfdf';
const bus = {
on() {},
emit: sinon.stub(),
};
const reduxStore = {
subscribe: (cb) => {
setTimeout(cb, 10);
},
getState: () => ({
api: {
selectedKind: kind,
selectedStory: story,
},
core: {
dataId,
},
}),
};
initPageBus(bus, reduxStore);
setTimeout(() => {
const event = bus.emit.args[0][0];
const payload = JSON.parse(bus.emit.args[0][1]);
expect(event).to.be.equal(`${dataId}.setCurrentStory`);
expect(payload).to.deep.equal({ kind, story });
done();
}, 20);
});
it('should send nothing to iframe if no preview data', (done) => {
const dataId = 'dasds';
const bus = {
on() {},
emit: sinon.stub(),
};
const reduxStore = {
subscribe: (cb) => {
setTimeout(cb, 10);
},
getState: () => ({
core: {
dataId,
},
}),
};
initPageBus(bus, reduxStore);
setTimeout(() => {
expect(bus.emit.callCount).to.be.equal(0);
done();
}, 20);
});
it('should call actions.preview.addAction', (done) => {
const dataId = 'dasds';
const bus = new EventEmitter();
const reduxStore = {
subscribe() {},
getState: () => ({
core: {
dataId,
},
}),
};
const action = { aa: 10 };
const actions = {
api: {
addAction(a) {
expect(a).to.deep.equal(action);
done();
},
},
};
initPageBus(bus, reduxStore, actions);
bus.emit(`${dataId}.addAction`, JSON.stringify({ action }));
});
it('should call actions.preview.setStories', (done) => {
const dataId = 'dasds';
const bus = new EventEmitter();
const reduxStore = {
subscribe() {},
getState: () => ({
core: {
dataId,
},
}),
};
const stories = [{ kind: 'aa' }];
const actions = {
api: {
setStories(s) {
expect(s).to.deep.equal(stories);
done();
},
},
};
initPageBus(bus, reduxStore, actions);
bus.emit(`${dataId}.setStories`, JSON.stringify({ stories }));
});
it('should dispatch SELECT_STORY', (done) => {
const dataId = 'dasds';
const bus = new EventEmitter();
const reduxStore = {
subscribe() {},
getState: () => ({
core: {
dataId,
},
}),
};
const kind = 'kk';
const story = 'ss';
const actions = {
api: {
selectStory(k, s) {
expect(k).to.be.equal(kind);
expect(s).to.be.equal(story);
done();
},
},
};
initPageBus(bus, reduxStore, actions);
bus.emit(`${dataId}.selectStory`, JSON.stringify({ kind, story }));
});
it('should call actions.shortcuts.handleEvent', (done) => {
const dataId = 'dasds';
const bus = new EventEmitter();
const reduxStore = {
subscribe() {},
getState: () => ({
core: {
dataId,
},
}),
};
const event = 1;
const actions = {
shortcuts: {
handleEvent(e) {
expect(e).to.be.equal(event);
done();
},
},
};
initPageBus(bus, reduxStore, actions);
bus.emit(`${dataId}.applyShortcut`, JSON.stringify({ event }));
});
});

View File

@ -1,23 +0,0 @@
export default function (provider, reduxStore, actions) {
const providerApi = {
onStory(cb) {
providerApi._onStoryCallback = cb;
},
addAction: actions.api.addAction,
setStories: actions.api.setStories,
selectStory: actions.api.selectStory,
handleShortcut: actions.shortcuts.handleEvent,
};
provider.handleAPI(providerApi);
const state = reduxStore.getState();
// subscribe to redux store and send down changes to pageBus.
reduxStore.subscribe(function () {
const { api } = reduxStore.getState();
if (!api) return;
providerApi._onStoryCallback(api.selectedKind, api.selectedStory);
});
}

View File

@ -1,8 +0,0 @@
import createPageBus from 'page-bus';
import initPagebus from './configs/init_pagebus';
export default {
load({ reduxStore, provider }, actions) {
initPagebus(provider, reduxStore, actions);
},
};