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

Interface updates #681

Merged
merged 2 commits into from
Sep 17, 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
3 changes: 1 addition & 2 deletions src/WidgetBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
DiffPropertyFunction,
DiffPropertyReaction,
DNode,
RegistryLabel,
Render,
VirtualDomNode,
WidgetMetaBase,
Expand Down Expand Up @@ -156,7 +155,7 @@ export class WidgetBase<P = WidgetProperties, C extends DNode = DNode> extends E
/**
* cached chldren map for instance management
*/
private _cachedChildrenMap: Map<RegistryLabel | Promise<WidgetBaseConstructor> | WidgetBaseConstructor, WidgetCacheWrapper[]>;
private _cachedChildrenMap: Map<string | number | Promise<WidgetBaseConstructor> | WidgetBaseConstructor, WidgetCacheWrapper[]>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it not RegistryLabel | number |...?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually should never have been registry label, the map always takes the key from properties and uses that (or the widget constructor). So I think it wasn't correct to support symbols.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 cool...


/**
* map of specific property diff functions
Expand Down
20 changes: 16 additions & 4 deletions src/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,26 @@ export interface WidgetProperties {
* The key for a widget. Used to differentiate uniquely identify child widgets for
* rendering and instance management
*/
key?: string;
key?: string | number;

/**
* Optional registry
*/
registry?: any;
}

/**
* Widget properties that require a key
*/
export interface KeyedWidgetProperties extends WidgetProperties {

/**
* The key for a widget. Used to differentiate uniquely identify child widgets for
* rendering and instance management
*/
key: string | number;
}

/**
*
*/
Expand Down Expand Up @@ -407,7 +419,7 @@ export interface WidgetBaseInterface<
* Meta Base type
*/
export interface WidgetMetaBase extends Destroyable {
has(key: string): boolean;
has(key: string | number): boolean;
}

/**
Expand All @@ -418,8 +430,8 @@ export interface WidgetMetaConstructor<T extends WidgetMetaBase> {
}

export interface NodeHandlerInterface extends Evented {
get(key: string): HTMLElement | undefined;
has(key: string): boolean;
get(key: string | number): HTMLElement | undefined;
has(key: string | number): boolean;
add(element: HTMLElement, properties: VNodeProperties): void;
addRoot(element: HTMLElement, properties: VNodeProperties): void;
addProjector(element: HTMLElement, properties: VNodeProperties): void;
Expand Down
8 changes: 4 additions & 4 deletions src/meta/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class Base extends Destroyable implements WidgetMetaBase {
private _invalidate: () => void;
protected nodeHandler: NodeHandlerInterface;

private _requestedNodeKeys = new Set<string>();
private _requestedNodeKeys = new Set<string | number>();

constructor(properties: WidgetMetaProperties) {
super();
Expand All @@ -15,15 +15,15 @@ export class Base extends Destroyable implements WidgetMetaBase {
this.nodeHandler = properties.nodeHandler;
}

public has(key: string): boolean {
public has(key: string | number): boolean {
return this.nodeHandler.has(key);
}

protected getNode(key: string): HTMLElement | undefined {
protected getNode(key: string | number): HTMLElement | undefined {
const node = this.nodeHandler.get(key);

if (!node && !this._requestedNodeKeys.has(key)) {
const handle = this.nodeHandler.on(key, () => {
const handle = this.nodeHandler.on(`${key}`, () => {
handle.destroy();
this._requestedNodeKeys.delete(key);
this.invalidate();
Expand Down