Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Use the new addons API #346

Merged
merged 8 commits into from
Aug 2, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests and lint errors
  • Loading branch information
thani-sh committed Aug 2, 2016
commit bebd823a984b1dc4b23a3252f07eebd4207d5ca9
2 changes: 1 addition & 1 deletion dist/client/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var Channel = function () {
}
}, {
key: 'removeListener',
value: function removeListener(type, handler) {
value: function removeListener() /* type, handler */{
// TODO get listener from a map[handler]listener
// this._pageBus.removeListener(type, listener);
}
Expand Down
8 changes: 0 additions & 8 deletions dist/client/manager/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,10 @@ var _qs = require('qs');

var _qs2 = _interopRequireDefault(_qs);

var _uuid = require('uuid');

var _uuid2 = _interopRequireDefault(_uuid);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _pageBus = require('page-bus');

var _pageBus2 = _interopRequireDefault(_pageBus);

var _storybookUi = require('@kadira/storybook-ui');

var _storybookAddons = require('@kadira/storybook-addons');
Expand Down
24 changes: 10 additions & 14 deletions dist/client/preview/client_api.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
'use strict';
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
var _toConsumableArray2 = require("babel-runtime/helpers/toConsumableArray");

var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);

var _extends2 = require('babel-runtime/helpers/extends');
var _extends2 = require("babel-runtime/helpers/extends");

var _extends3 = _interopRequireDefault(_extends2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass2 = require("babel-runtime/helpers/createClass");

var _createClass3 = _interopRequireDefault(_createClass2);

var _uuid = require('uuid');

var _uuid2 = _interopRequireDefault(_uuid);

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

var ClientApi = function () {
Expand All @@ -41,22 +37,22 @@ var ClientApi = function () {
}

(0, _createClass3.default)(ClientApi, [{
key: 'setAddon',
key: "setAddon",
value: function setAddon(addon) {
this._addons = (0, _extends3.default)({}, this._addons, addon);
}
}, {
key: 'addDecorator',
key: "addDecorator",
value: function addDecorator(decorator) {
this._globalDecorators.push(decorator);
}
}, {
key: 'clearDecorators',
key: "clearDecorators",
value: function clearDecorators() {
this._globalDecorators = [];
}
}, {
key: 'storiesOf',
key: "storiesOf",
value: function storiesOf(kind, m) {
var _this = this;

Expand Down Expand Up @@ -115,7 +111,7 @@ var ClientApi = function () {
return api;
}
}, {
key: 'getStorybook',
key: "getStorybook",
value: function getStorybook() {
var _this2 = this;

Expand Down
2 changes: 1 addition & 1 deletion src/client/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class Channel {
this._pageBus.emit(`${this._dataId}.${type}`, payload);
}

removeListener(type, handler) {
removeListener(/* type, handler */) {
// TODO get listener from a map[handler]listener
// this._pageBus.removeListener(type, listener);
}
Expand Down
2 changes: 0 additions & 2 deletions src/client/manager/provider.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Preview from './preview';
import qs from 'qs';
import UUID from 'uuid';
import React from 'react';
import createPageBus from 'page-bus';
import { Provider } from '@kadira/storybook-ui';
import addons from '@kadira/storybook-addons';
import Channel from '../channel';
Expand Down
52 changes: 0 additions & 52 deletions src/client/preview/__tests__/client_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ class StoryStore {
}
}

class PageBus {
constructor() {
this.emits = [];
}

emit(type, ...args) {
this.emits.push({ type, args });
}
}

describe('preview.client_api', () => {
describe('setAddon', () => {
it('should register addons', () => {
Expand Down Expand Up @@ -220,48 +210,6 @@ describe('preview.client_api', () => {
});
});

describe('action', () => {
it('should emit "addAction"', () => {
const api = new ClientAPI({});
api._pageBus = new PageBus();
const action = api.action('test-action');
action(1, 'a', [1], { a: 1 }, { preventDefault() {} });
expect(api._pageBus.emits.length).to.equal(1);
expect(api._pageBus.emits[0].type).to.equal('addAction');
expect(typeof api._pageBus.emits[0].args[0].action.id).to.equal('string');
expect(api._pageBus.emits[0].args[0].action.data).to.deep.equal({
name: 'test-action',
args: [1, 'a', [1], { a: 1 }, '[SyntheticEvent]'],
});
});
});

describe('linkTo', () => {
it('should emit "selectStory"', () => {
const api = new ClientAPI({});
api._pageBus = new PageBus();
api.linkTo('test-kind', 'test-story')();
expect(api._pageBus.emits.length).to.equal(1);
expect(api._pageBus.emits[0].type).to.equal('selectStory');
expect(api._pageBus.emits[0].args[0]).to.deep.equal({
kind: 'test-kind',
story: 'test-story',
});
});

it('should support function args', () => {
const api = new ClientAPI({});
api._pageBus = new PageBus();
api.linkTo(a => `${a}-kind`, a => `${a}-story`)('test');
expect(api._pageBus.emits.length).to.equal(1);
expect(api._pageBus.emits[0].type).to.equal('selectStory');
expect(api._pageBus.emits[0].args[0]).to.deep.equal({
kind: 'test-kind',
story: 'test-story',
});
});
});

describe('getStorybook', () => {
it('should return storybook when empty', () => {
const storyStore = new StoryStore();
Expand Down
2 changes: 0 additions & 2 deletions src/client/preview/client_api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import UUID from 'uuid';

export default class ClientApi {
constructor({ channel, storyStore }) {
// channel can be null when running in node
Expand Down