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

Custom element wrapper #768

Merged
merged 3 commits into from
Nov 13, 2017
Merged

Custom element wrapper #768

merged 3 commits into from
Nov 13, 2017

Conversation

agubler
Copy link
Member

@agubler agubler commented Nov 13, 2017

Type: feature

The following has been addressed in the PR:

  • There is a related issue
  • All code matches the style guide
  • Unit or Functional tests are included in the PR

Description:

For custom elements that are written to deal with Dojo 2 custom element children only, add support for widget-core to treat them as widgets meaning that they can be authored without needing to add specific code to deal with custom elements.

Enabling usage as follows:

Using as a Dojo Widget:

class Example extends WidgetBase {

  private _onSelected(data: any) {
    console.log(data);
  }

  protected render() {
    return w(Menu, { onSelected: this._onSelected }, [
      w(MenuItem, { key: 'a', title: 'Menu Item A' }),
      w(MenuItem, { key: 'b', title: 'Menu Item B', selected: true }),
      w(MenuItem, { key: 'c', title: 'Menu Item C' })
    ]);
  }
}

Using as a Custom Element:

<demo-menu id="menu">
  <demo-menu-item id="a" title="Menu Item A"></demo-menu-item>
  <demo-menu-item id="b" title="Menu Item B"></demo-menu-item>
  <demo-menu-item id="c" title="Menu Item C" selected></demo-menu-item>
</demo-menu>
<script>
  a.data = { foo: 'bar' };
  menu.addEventListener('selected', function(event) {
    const detail = event.detail;
    console.log(detail);
  });
</script>

@@ -102,6 +108,11 @@ export interface CustomElementDescriptor {
* Initialization function called before the widget is created (for custom property setting)
*/
initialization?: CustomElementInitializer;

/**
*
Copy link
Member Author

Choose a reason for hiding this comment

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

jsdoc


export type DomToWidgetWrapper = Constructor<WidgetBase<DomToWidgetWrapperProperties>>;

export function DomToWidgetWrapper(domNode: CustomElement): DomToWidgetWrapper {
Copy link
Member Author

Choose a reason for hiding this comment

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

add some jsdoc

@agubler agubler requested a review from kitsonk November 13, 2017 15:05
@@ -60,6 +61,11 @@ export interface CustomElementInitializer {
(properties: WidgetProperties): void;
}

export enum ChildrenType {
Copy link
Member

Choose a reason for hiding this comment

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

Just a question/random thought... for HNode and VNode we use symbols to tag the types, here we are using string enums. Conscious decision or unconscious?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was conscious as an enum seemed more appropriate as part of a consumer API

@agubler agubler merged commit 22e6498 into dojo:master Nov 13, 2017
@dylans dylans added this to the beta.4 milestone Jan 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants