Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Support Addons #20

Merged
merged 1 commit into from
Jun 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
66 changes: 66 additions & 0 deletions dist/client/configure/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use strict';

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; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var ClientApi = function () {
function ClientApi(stories) {
_classCallCheck(this, ClientApi);

this._stories = stories;
this._addons = {};
}

_createClass(ClientApi, [{
key: 'setAddon',
value: function setAddon(addon) {
Object.assign(this._addons, addon);
}
}, {
key: 'configure',
value: function configure(loaders, module) {
var _this = this;

loaders();
if (module.hot) {
module.hot.accept(function () {
return _this._stories.emit('change');
});
}
}
}, {
key: 'storiesOf',
value: function storiesOf(kind) {
return new KindApi(this._stories, this._addons, kind);
}
}]);

return ClientApi;
}();

exports.default = ClientApi;

var KindApi = exports.KindApi = function () {
function KindApi(stories, addons, kind) {
_classCallCheck(this, KindApi);

this.kind = kind;
this._stories = stories;
Object.assign(this, addons);
}

_createClass(KindApi, [{
key: 'add',
value: function add(story, fn) {
this._stories.add(this.kind, story, fn);
return this;
}
}]);

return KindApi;
}();
32 changes: 9 additions & 23 deletions dist/client/configure/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,21 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.stories = undefined;
exports.configure = configure;
exports.storiesOf = storiesOf;
exports.setAddon = exports.storiesOf = exports.configure = exports.client = exports.stories = undefined;

var _store = require('./store');

var _store2 = _interopRequireDefault(_store);

var _client = require('./client');

var _client2 = _interopRequireDefault(_client);

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

var stories = exports.stories = new _store2.default();
var client = exports.client = new _client2.default(stories);

//
function configure(loaders, module) {
loaders();

if (module.hot) {
module.hot.accept(function () {
stories.emit('change');
});
}
}

//
function storiesOf(kind) {
var api = {};
api.add = function (story, fn) {
stories.add(kind, story, fn);
return api;
};
return api;
}
var configure = exports.configure = client.configure.bind(client);
var storiesOf = exports.storiesOf = client.storiesOf.bind(client);
var setAddon = exports.setAddon = client.setAddon.bind(client);
8 changes: 7 additions & 1 deletion dist/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.storiesOf = exports.configure = undefined;
exports.setAddon = exports.storiesOf = exports.configure = undefined;

var _configure = require('./configure/');

Expand All @@ -19,6 +19,12 @@ Object.defineProperty(exports, 'storiesOf', {
return _configure.storiesOf;
}
});
Object.defineProperty(exports, 'setAddon', {
enumerable: true,
get: function get() {
return _configure.setAddon;
}
});
exports.PreviewComponent = PreviewComponent;

var _react = require('react');
Expand Down
34 changes: 34 additions & 0 deletions src/client/configure/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export default class ClientApi {
constructor(stories) {
this._stories = stories;
this._addons = {};
}

setAddon(addon) {
Object.assign(this._addons, addon);
}

configure(loaders, module) {
loaders();
if (module.hot) {
module.hot.accept(() => this._stories.emit('change'));
}
}

storiesOf(kind) {
return new KindApi(this._stories, this._addons, kind);
}
}

export class KindApi {
constructor(stories, addons, kind) {
this.kind = kind;
this._stories = stories;
Object.assign(this, addons);
}

add(story, fn) {
this._stories.add(this.kind, story, fn);
return this;
}
}
25 changes: 5 additions & 20 deletions src/client/configure/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
import StoryStore from './store';
import ClientApi from './client';

export const stories = new StoryStore();
export const client = new ClientApi(stories);

//
export function configure(loaders, module) {
loaders();

if (module.hot) {
module.hot.accept(() => {
stories.emit('change');
});
}
}

//
export function storiesOf(kind) {
const api = {};
api.add = (story, fn) => {
stories.add(kind, story, fn);
return api;
};
return api;
}
export const configure = client.configure.bind(client);
export const storiesOf = client.storiesOf.bind(client);
export const setAddon = client.setAddon.bind(client);
1 change: 1 addition & 0 deletions src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { stories } from './configure';
// export configuration API functions
export { configure } from './configure/';
export { storiesOf } from './configure/';
export { setAddon } from './configure/';

// export the function to generate the preview component
export function PreviewComponent({port, host = 'localhost'}) {
Expand Down