tldr: Extend WebComponent to define your own components.
- Create an html (and css) file for your component in a new folder
- Create a new ts class that extends
WebComponent - Use the component either in HTML or in TypeScript:
- in HTML:
<my-component></my-component> - in TypeScript:
const myComponent = new MyComponent()
- in HTML:
- (don't forget to call
WebComponentLoader.loadAll().then(() => {...})at the start of your application)
For examples, see the ExampleWebComponent
tldr: Communication is based on the pubSub pattern. Extend Observable to make your class observable, use EventBus for global communication.
Extending Observable provides a class with basic pubSub functionality:
- create a class that extends
Observable - call
.addEventListeneron objects of that class to subscribe to events - call
notifyAllto publish an event to all subscribers
For an example, see Observable
If you wish to send global events, you can use the EventBus class:
- import the
EventBussingleton - call
.addEventListenerto subscribe to events - call
.notifyAllto publish an event to all subscribers
For an example, see EventBus
tldr: Create Models to define data structures, use them via States in your Components. Use GlobalState to store globally needed States.
Model represents a basic data structure thats used in your application.
NOTE: Use State to make observe/manipulate Models. Don't use Models directly.
- extend
Modeland define the properties of your model
For an example, see Model
State is a wrapper class that allows you to make any existing object observable (not just Models).
- use
new State(value)to create a newStateobject - call
.addEventListenerto subscribe to changes - call
liveData.valueto get the current value - call
liveData.value = newValueto update the value
For an example, see State
GlobalState is a singleton, where States, which are needed in many Components, should be stored.
That way, they can be accessed from anywhere in the application.
- import the
GlobalStatesingleton - use
GlobalState.addModel(model)to add a model to the store - use GlobalState.findModel(), GlobalState.findModels() and GlobalState.getModelById() retrieve models from the store
- (don't forget to call GlobalState.init() at the start of the application)
For an example, see GlobalState
tldr: Use DataManager to fetch/save data as Models from external APIs or Databases.
DataManager is a singleton, in which you define functions to fetch/save Models.
- import the
DataManagersingleton - use any of the
DataManagerfunctions to retrieve data as Models - (don't forget to call DataManager.init() at the start of the application)