-
-
Notifications
You must be signed in to change notification settings - Fork 969
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15d5bf3
commit 1198c23
Showing
2 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// This interface is only exposed and any Riot component will receive the following properties | ||
export interface RiotCoreComponent { | ||
// automatically generated on any component instance | ||
props: object | ||
root: HTMLElement | ||
name?: string | ||
slots: any[] | ||
mount( | ||
element: HTMLElement, | ||
initialState?: object, | ||
parentScope?: object | ||
): RiotComponent | ||
update( | ||
newState?: object, | ||
parentScope?: object | ||
): RiotComponent | ||
unmount(keepRootElement: boolean): RiotComponent | ||
|
||
// Helpers | ||
$(selector: string): HTMLElement | ||
$$(selector: string): [HTMLElement] | ||
} | ||
|
||
export interface RiotComponentShell { | ||
css?: string | ||
exports?: any | ||
name?: string | ||
// TODO: add the @riotjs/dom-bindings types | ||
template(): any | ||
} | ||
|
||
// All the RiotComponent Public interface properties are optional | ||
export interface RiotComponent extends RiotCoreComponent { | ||
// optional on the component object | ||
state?: object | ||
|
||
// optional alias to map the children component names | ||
components?: { | ||
[key: string]: RiotComponentShell | ||
} | ||
|
||
// state handling methods | ||
shouldUpdate?(newProps: object, currentProps: object): boolean | ||
|
||
// lifecycle methods | ||
onBeforeMount?(currentProps: object, currentState: object): void | ||
onMounted?(currentProps: object, currentState: object): void | ||
onBeforeUpdate?(currentProps: object, currentState: object): void | ||
onUpdated?(currentProps: object, currentState: object): void | ||
onBeforeUnmount?(currentProps: object, currentState: object): void | ||
onUnmounted?(currentProps: object, currentState: object): void | ||
} | ||
|
||
export type RegisteredComponentsMap = Map<string, () => RiotComponent> | ||
export type ComponentEnhancer = (component: RiotComponent) => RiotComponent | ||
export type InstalledPluginsSet = Set<ComponentEnhancer> | ||
|
||
declare module 'riot' { | ||
export function register(componentName: string, shell: RiotComponentShell): RegisteredComponentsMap | ||
export function unregister(componentName: string): RegisteredComponentsMap | ||
export function mount(selector: string, componentName: string, initialProps: object): RiotComponent[] | ||
export function unmount(selector: string):HTMLElement[] | ||
export function install(plugin: ComponentEnhancer):InstalledPluginsSet | ||
export function uninstall(plugin: ComponentEnhancer):InstalledPluginsSet | ||
export function version: string | ||
export function component(shell: RiotComponentShell):(el: HTMLElement, initialProps?: object) => RiotComponent | ||
} |