Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
[bugfix] #1 prevent thrown error while unregister unregistered component
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Mollweide committed Jul 7, 2017
1 parent 7e4195a commit acfbe29
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 145 deletions.
5 changes: 4 additions & 1 deletion TerrificBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ export class TerrificBridge {
}

const id = node.getAttribute("data-t-id");
if (!id || id === null) {
return void 0;
}
const tModule = this._app.getModuleById(id);

if (bridge._config.debug) {
Expand Down Expand Up @@ -321,7 +324,7 @@ export class TerrificBridge {
}

/**
* The TerrificBridgeInstance is a singleton and
* The TerrificBridgeInstance is a singleton and
* will be instanciated here.
*/
TerrificBridgeInstance = new TerrificBridge(!(NODE_ENV === "production"));
Expand Down
34 changes: 34 additions & 0 deletions TerrificBridge.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,39 @@ describe("TerrificBridge", () => {
});
});

it("should unregister unregistered terrific component", () => {
TerrificBridge.reset();
TerrificBridge.configure({ debug: true });

const uiStopStub = sinon.spy();

T.Module.CanRegister = T.createModule({
start(resolve) {
resolve();
},
stop() {
uiStopStub();
this._events.disconnect();
}
});

class CanRegister extends Component {
componentWillUnmount() {
TerrificBridge.unregisterComponent(this);
}

render() {
return <div id="component" data-t-name="CanRegister" />;
}
}

const tree = mount(<CanRegister />);
TerrificBridge.load();
tree.unmount();

expect(uiStopStub.callCount).toEqual(0);
});

describe("components", () => {
describe("registration", () => {
it("should mount components successfully", () => {
Expand Down Expand Up @@ -245,6 +278,7 @@ describe("TerrificBridge", () => {

expect(uiStopStub.callCount).toEqual(1);
});

it("should log unregistration errors from terrific components", () => {
TerrificBridge.reset();
TerrificBridge.configure({ debug: true });
Expand Down
7 changes: 5 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ var TerrificBridge = function () {
}

var id = node.getAttribute("data-t-id");
if (!id || id === null) {
return void 0;
}
var tModule = _this2._app.getModuleById(id);

if (bridge._config.debug) {
Expand Down Expand Up @@ -395,14 +398,14 @@ var TerrificBridge = function () {
}, {
key: "terrific",
get: function get() {
return this._t;
return this._t || window.T || void 0;
}
}]);
return TerrificBridge;
}();

/**
* The TerrificBridgeInstance is a singleton and
* The TerrificBridgeInstance is a singleton and
* will be instanciated here.
*/

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-terrific-bridge",
"version": "1.2.6",
"version": "1.2.7",
"main": "dist/index.js",
"author": "Jan Biasi <biasijan@gmail.com>",
"contributors": [
Expand Down

0 comments on commit acfbe29

Please sign in to comment.