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

Delete the clear_state commlessOnly argument #1354

Merged
merged 2 commits into from
May 16, 2017
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
11 changes: 3 additions & 8 deletions jupyter-js-widgets/src/manager-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,11 @@ abstract class ManagerBase<T> {

/**
* Close all widgets and empty the widget state.
* @param commlessOnly should only commless widgets be removed
* @return promise that resolves when the widget state is cleared.
* @return Promise that resolves when the widget state is cleared.
*/
clear_state(commlessOnly: boolean): Promise<void> {
clear_state(): Promise<void> {
return utils.resolvePromisesDict(this._models).then((models) => {
Object.keys(models).forEach((id) => {
if (!commlessOnly || models[id].comm) {
models[id].close();
}
});
Object.keys(models).forEach(id => models[id].close());
this._models = {};
});
};
Expand Down
2 changes: 0 additions & 2 deletions jupyter-js-widgets/test/src/dummy-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class MockComm {
this.comm_id = `mock-comm-id-${numComms}`;
numComms += 1;
}
// Somehow the mock comm should trigger a close event?
on_close(fn) {
this._on_close = fn;
};
Expand All @@ -24,7 +23,6 @@ class MockComm {
if (this._on_close) {
this._on_close();
}
console.error(this._on_close);
};
send() {};
comm_id: string;
Expand Down
20 changes: 11 additions & 9 deletions jupyter-js-widgets/test/src/manager_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,29 +149,31 @@ describe("ManagerBase", function() {
});

describe('clear_state', function() {
it('exists', function() {
expect(this.managerBase.clear_state).to.not.be.undefined;
});
it('clears the model dictionary', async function() {
it('clears the model dictionary and closes widgets', async function() {
let spec = {
model_name: 'IntSliderModel',
model_module: 'jupyter-js-widgets',
model_module_version: '3.0.0',
};
let mSpec1 = { ...spec, comm: new MockComm()};
let mSpec2 = { ...spec, comm: new MockComm()};
let comm1 = new MockComm();
let comm2 = new MockComm();
sinon.spy(comm1, 'close');
sinon.spy(comm2, 'close');
let mSpec1 = { ...spec, comm: comm1};
let mSpec2 = { ...spec, comm: comm2};
let manager = this.managerBase;
let model1 = await manager.new_model(mSpec1);
let model2 = await manager.new_model(mSpec2);
let m1 = await manager.get_model(model1.id);
expect(await manager.get_model(model1.id)).to.be.equal(model1);
expect(await manager.get_model(model2.id)).to.be.equal(model2);
await manager.clear_state();
expect(manager.get_model(model1.id)).to.be.undefined;
expect(manager.get_model(model2.id)).to.be.undefined;
expect((comm1.close as any).calledOnce).to.be.true;
expect((comm2.close as any).calledOnce).to.be.true;
expect(model1.comm).to.be.undefined;
expect(model2.comm).to.be.undefined;
});
it('clears only commless widgets if comlessOnly is true');
it('closes the widgets');
});

describe('get_state', function() {
Expand Down
6 changes: 3 additions & 3 deletions jupyter-js-widgets/test/src/widget_date_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('DatePickerView', function() {
});

it('initial date value', function() {
const testDate = new Date(2017, 2, 25); // initial date value
const testDate = new Date("2017-02-25");
this.model.set('value', testDate);
const options = { model: this.model };
const view = new widgets.DatePickerView(options);
Expand All @@ -72,7 +72,7 @@ describe('DatePickerView', function() {
view.render();

// Simulate setting the date in the datepicker
const testDate = new Date(2015, 2, 22);
const testDate = new Date("2015-02-22");
const datepicker = getDatepicker(view.el);
datepicker.valueAsDate = testDate;
datepicker.dispatchEvent(new Event('change', {"bubbles":true}));
Expand All @@ -87,7 +87,7 @@ describe('DatePickerView', function() {
const view = new widgets.DatePickerView(options);
view.render();

const testDate = new Date(2015, 2, 22);
const testDate = new Date("2015-02-22");
this.model.set('value', testDate);
const datepicker = getDatepicker(view.el);
expect(datepicker.valueAsDate.getTime())
Expand Down