Skip to content

Commit

Permalink
Added a way to pause updates without dissabling components
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperMetal committed Dec 14, 2018
1 parent c24a8a4 commit 7b9977a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bloomstack/panda",
"version": "1.0.2",
"version": "1.0.3",
"description": "A generic aggregate composition library. Meant to be light weight and easily extensible.",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
14 changes: 13 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export class Component {
this._components = {}
this._parent = parent;
this._children = [];
this._canUpdate = true;

this._baseComponent = baseComponent || null;
}
Expand All @@ -157,6 +158,14 @@ export class Component {
return this._started;
}

get canUpdate() {
return this._canUpdate;
}

set canUpdate(value) {
this._canUpdate = value;
}

/**
* Returns true if this component is the root component.
*/
Expand Down Expand Up @@ -371,7 +380,10 @@ export class Component {

this._started = true;

await this.update();
if ( this.canUpdate ) {
await this.update();
}

await this.broadcast('onLateStart');

return this;
Expand Down
9 changes: 9 additions & 0 deletions tests/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ describe("Component", async () => {
expect(comp.baseComponent === baseComp).toBe(true);
expect(comp.parent === parentComp).toBe(true);
});

it("Pause updates", async () => {
let comp = await Component.create();
comp.onUpdate = function() { /* do nothing */ }
spyOn(comp, 'onUpdate').andCallThrough();
comp.canUpdate = false;
await comp.init();
expect(comp.onUpdate).toNotHaveBeenCalled();
});
})


Expand Down

0 comments on commit 7b9977a

Please sign in to comment.