Skip to content

Commit

Permalink
Make tab refreshable, #571
Browse files Browse the repository at this point in the history
  • Loading branch information
cocopon committed Sep 5, 2023
1 parent 8f51679 commit 9855f3e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
12 changes: 9 additions & 3 deletions packages/core/src/blade/common/api/container-blade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import {PluginPool} from '../../../plugin/pool.js';
import {ContainerBladeController} from '../controller/container-blade.js';
import {BladeApi} from './blade.js';
import {RackApi} from './rack.js';
import {Refreshable} from './refreshable.js';

export class ContainerBladeApi<
C extends ContainerBladeController,
> extends BladeApi<C> {
export class ContainerBladeApi<C extends ContainerBladeController>
extends BladeApi<C>
implements Refreshable
{
/**
* @hidden
*/
Expand All @@ -19,6 +21,10 @@ export class ContainerBladeApi<

this.rackApi_ = new RackApi(controller.rackController, pool);
}

public refresh(): void {
this.rackApi_.refresh();
}
}

export function isContainerBladeApi(
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/blade/folder/api/folder-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,13 @@ describe(FolderApi.name, () => {
});
});
});

it('should refresh items', () => {
const api = createApi();
const PARAMS = {param: 1};
const i = api.addBinding(PARAMS, 'param');
PARAMS.param += 1;
api.refresh();
assert.strictEqual(i.controller.value.rawValue, 2);
});
});
4 changes: 0 additions & 4 deletions packages/core/src/blade/folder/api/folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,4 @@ export class FolderApi
});
return this;
}

public refresh(): void {
this.rackApi_.refresh();
}
}
4 changes: 0 additions & 4 deletions packages/core/src/blade/tab/api/tab-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,4 @@ export class TabPageApi
public addBlade(params: BaseBladeParams): BladeApi {
return this.rackApi_.addBlade(params);
}

public refresh(): void {
this.rackApi_.refresh();
}
}
21 changes: 21 additions & 0 deletions packages/core/src/blade/tab/api/tab-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,25 @@ describe(TabApi.name, () => {
api.pages[0].selected = true;
assert.deepStrictEqual(selectedIndexes, [1, 2, 0]);
});

it('should refresh pages', () => {
const doc = createTestWindow().document;
const c = new TabController(doc, {
blade: createBlade(),
viewProps: ViewProps.create(),
});
const pool = createDefaultPluginPool();
const api = new TabApi(c, pool);
api.addPage({title: 'foo'});
api.addPage({title: 'bar'});

const PARAMS = {param: 1};
const i0 = api.pages[0].addBinding(PARAMS, 'param');
const i1 = api.pages[1].addBinding(PARAMS, 'param');
PARAMS.param += 1;
api.refresh();

assert.strictEqual(i0.controller.value.rawValue, 2);
assert.strictEqual(i1.controller.value.rawValue, 2);
});
});

0 comments on commit 9855f3e

Please sign in to comment.