Skip to content

Commit

Permalink
Merge pull request #335 from kadirahq/fix-hmr-duplicate-decorator
Browse files Browse the repository at this point in the history
Clear decorators on module dispose
  • Loading branch information
Muhammed Thanish authored Jul 26, 2016
2 parents ecfd264 + 6674abc commit 0a9b595
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions dist/client/preview/client_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ var ClientApi = function () {
value: function addDecorator(decorator) {
this._globalDecorators.push(decorator);
}
}, {
key: 'clearDecorators',
value: function clearDecorators() {
this._globalDecorators = [];
}
}, {
key: 'storiesOf',
value: function storiesOf(kind, m) {
Expand Down
5 changes: 5 additions & 0 deletions dist/client/preview/config_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var _createClass3 = _interopRequireDefault(_createClass2);

var _actions = require('./actions');

var _ = require('./');

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

var ConfigApi = function () {
Expand Down Expand Up @@ -67,6 +69,9 @@ var ConfigApi = function () {
module.hot.accept(function () {
setTimeout(render);
});
module.hot.dispose(function () {
(0, _.clearDecorators)();
});
}

render();
Expand Down
3 changes: 2 additions & 1 deletion dist/client/preview/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.configure = exports.addDecorator = exports.setAddon = exports.linkTo = exports.action = exports.storiesOf = undefined;
exports.configure = exports.clearDecorators = exports.addDecorator = exports.setAddon = exports.linkTo = exports.action = exports.storiesOf = undefined;

require('es6-shim');

Expand Down Expand Up @@ -62,6 +62,7 @@ var action = exports.action = clientApi.action.bind(clientApi);
var linkTo = exports.linkTo = clientApi.linkTo.bind(clientApi);
var setAddon = exports.setAddon = clientApi.setAddon.bind(clientApi);
var addDecorator = exports.addDecorator = clientApi.addDecorator.bind(clientApi);
var clearDecorators = exports.clearDecorators = clientApi.clearDecorators.bind(clientApi);
var configure = exports.configure = configApi.configure.bind(configApi);

// initialize the UI
Expand Down
4 changes: 4 additions & 0 deletions src/client/preview/client_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export default class ClientApi {
this._globalDecorators.push(decorator);
}

clearDecorators() {
this._globalDecorators = [];
}

storiesOf(kind, m) {
if (m && m.hot) {
m.hot.dispose(() => {
Expand Down
5 changes: 5 additions & 0 deletions src/client/preview/config_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
clearError,
} from './actions';

import { clearDecorators } from './';

export default class ConfigApi {
constructor({ pageBus, storyStore, reduxStore }) {
this._pageBus = pageBus;
Expand Down Expand Up @@ -42,6 +44,9 @@ export default class ConfigApi {
module.hot.accept(() => {
setTimeout(render);
});
module.hot.dispose(() => {
clearDecorators();
});
}

render();
Expand Down
1 change: 1 addition & 0 deletions src/client/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const action = clientApi.action.bind(clientApi);
export const linkTo = clientApi.linkTo.bind(clientApi);
export const setAddon = clientApi.setAddon.bind(clientApi);
export const addDecorator = clientApi.addDecorator.bind(clientApi);
export const clearDecorators = clientApi.clearDecorators.bind(clientApi);
export const configure = configApi.configure.bind(configApi);

// initialize the UI
Expand Down

0 comments on commit 0a9b595

Please sign in to comment.