Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WidgetFactory

A widget factory for PAM applications.

To add your own widgets and properties to the PAM markup, use this factory to make them available to the parser.

For example, if you had a PuppyWidget that you wanted to use:

WidgetFactory.global.registerWidget("Puppy", PuppyWidget);

Now you can use your PuppyWidget in PAM:

 <TabPanel>
     <Puppy />
     <Puppy />
 <TabPanel>

You can name widgets whatever you like, as long as they are valid XML tag names. That means you can have a Dog.Puppy, _Puppy42, and even ಠ_ಠ as names!

Attached Properties

Attached Properties follow along the same lines as above, with one important caveat: All Attached Property names must begin with an uppercase character! This is to distinguish them from regular attributes, which are copied to the HTML DOM node directly.

 <TabPanel>
     <Puppy MyPuppyProp="5" /> <!--works-->
     <Puppy myOtherProp="3" /> <!--doesn't work-->
 </TabPanel>

Another thing to keep in mind is that right now, AttachedProperties must be strings. I hope to fix this sooner or later, but don't have a workaround right now.

Hierarchy

  • WidgetFactory

Index

Type aliases

Static ConstructorType

ConstructorType: object

A convenience type to express a constructor in a covariant way.

internal

Type declaration

  • constructor: function
    • new __type(...args: any[]): Widget
    • Parameters

      • Rest ...args: any[]

      Returns Widget

Properties

Private ctorRegistry

ctorRegistry: Map<string, object> = new Map<string, WidgetFactory.ConstructorType>()

Private propRegistry

propRegistry: Map<string, IAttachedProperty<Widget, string>> = new Map<string, WidgetFactory.IAttachedProperty>()

Static global

global: WidgetFactory = new WidgetFactory()

A default global factory for PAM

Methods

createWidget

  • createWidget(name: string): Widget
  • Instantiate a new widget from the factory.

    Parameters

    • name: string

      The registered name of the widget to create

    Returns Widget

getProperty

  • Get an attached property from the factory.

    Parameters

    • name: string

      The registered name of the property

    Returns IAttachedProperty

registerProperty

  • Register an attached property into the factory.

    Parameters

    • name: string

      What name this property will be referenced by.

    • prop: IAttachedProperty

      The AttachedProperty being registered.

      Notes

      Attached property names must begin with an uppercase letter! This allows the loader to differentiate between HTML attributes and attached properties. They must also be valid XML attribute names, but this function won't check for that. Of note; attribute names may include a dot.

    Returns void

registerWidget

  • Register a new widget into the factory.

    Parameters

    • name: string

      What name this widget will be referenced by in the markup.

    • ctor: ConstructorType

      The constructor for the widget being registered.

      Notes

      The constructor should take no arguments.

      TODO: Should we add additional props for things like attribute validation and has-children?

      TODO: Should we perform normalization? HTML (and SGML in general) is generally case insensitive, whereas XML is generally case sensitive. This may cause problems, either in user understanding or interfacing with the HTML DOM.

    Returns void

Generated using TypeDoc