-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
13 changed files
with
152 additions
and
10 deletions.
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
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,17 @@ | ||
import Hooks from '@poppinss/hooks' | ||
import { Component } from './component.js' | ||
import { View } from './view.js' | ||
import { ViewContext } from './view_context.js' | ||
|
||
export type ComponentHookEvents = { | ||
boot: [[Component], []] | ||
mount: [[Component, any], [string]] | ||
hydrate: [[Component], []] | ||
update: [[Component, string, string, any], []] | ||
call: [[Component, string, any[], boolean], []] | ||
exception: [[Component, unknown, boolean], []] | ||
render: [[Component, View, any], [string, (html: string) => any, ViewContext]] | ||
dehydrate: [[Component], []] | ||
} | ||
|
||
export type ComponentHook = (hooks: Hooks<ComponentHookEvents>) => void |
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,15 @@ | ||
import { ComponentHook, ComponentHookEvents } from './component_hook.js' | ||
import Hooks from '@poppinss/hooks' | ||
|
||
export class ComponentHookRegistry { | ||
components: ComponentHook[] = [] | ||
hooks: Hooks<ComponentHookEvents> | ||
|
||
constructor() { | ||
this.hooks = new Hooks() | ||
} | ||
|
||
async register(Hook: ComponentHook) { | ||
Hook(this.hooks) | ||
} | ||
} |
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,18 @@ | ||
import Hooks from '@poppinss/hooks' | ||
import { ComponentHookEvents } from '../../component_hook.js' | ||
|
||
export const LifecycleComponentHook = (hooks: Hooks<ComponentHookEvents>) => { | ||
hooks.add('boot', async (component) => { | ||
await component.hooks.runner('boot').run() | ||
await component.hooks.runner('initialize').run() | ||
await component.hooks.runner('mount').run() | ||
await component.hooks.runner('booted').run() | ||
}) | ||
|
||
hooks.add('render', async (component, view, data) => { | ||
await component.hooks.runner('rendering').run(view, data) | ||
return async (html) => { | ||
await component.hooks.runner('rendered').run(view, html) | ||
} | ||
}) | ||
} |
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,37 @@ | ||
import Hooks from '@poppinss/hooks' | ||
import { View } from '../../../view.js' | ||
|
||
type Events = { | ||
boot: [[], []] | ||
initialize: [[], []] | ||
mount: [[], []] | ||
hydrate: [[], []] | ||
exception: [[unknown, boolean], []] | ||
rendering: [[View, any], []] | ||
rendered: [[View, string], []] | ||
dehydrate: [[], []] | ||
booted: [[], []] | ||
} | ||
|
||
type Constructor = new (...args: any[]) => { | ||
mount?(...args: any[]): void | ||
} | ||
|
||
export function LifecycleHooks<T extends Constructor>(superclass: T) { | ||
return class LifecycleHooksImpl extends superclass { | ||
#hooks: Hooks<Events> | ||
|
||
constructor(...args: any[]) { | ||
super(...args) | ||
this.#hooks = new Hooks() | ||
|
||
if (this.mount) { | ||
this.#hooks.add('mount', this.mount) | ||
} | ||
} | ||
|
||
public get hooks(): Hooks<Events> { | ||
return this.#hooks | ||
} | ||
} | ||
} |
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,4 @@ | ||
import Hooks from '@poppinss/hooks' | ||
import { ComponentHookEvents } from '../../component_hook.js' | ||
|
||
export const ValidationComponentHook = (hooks: Hooks<ComponentHookEvents>) => {} |
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,5 @@ | ||
export type Constructor = new (...args: any[]) => {} | ||
|
||
export function HandlesValidation<T extends Constructor>(superclass: T) { | ||
return class HandlesValidationImpl extends superclass {} | ||
} |
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
Empty file.
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 @@ | ||
export class ViewContext {} |