Skip to content

Commit

Permalink
fix: run superCharged plugin at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Nov 7, 2023
1 parent d0d7dd0 commit f577463
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions src/edge/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ export class Edge {
return new Edge(options)
}

/**
* An array of bundled plugins
*/
#bundledPlugins: {
fn: PluginFn<any>
executed: boolean
options?: any
}[] = []

/**
* An array of registered plugins
*/
Expand Down Expand Up @@ -97,10 +106,11 @@ export class Edge {
this.registerTag(Tags[name as keyof typeof Tags])
})

/**
* Registering super charged plugin
*/
this.use(pluginSuperCharged, { recurring: !options.cache })
this.#bundledPlugins.push({
fn: pluginSuperCharged,
executed: false,
options: { recurring: !options.cache },
})
}

/**
Expand Down Expand Up @@ -128,6 +138,9 @@ export class Edge {
* Execute plugins
*/
#executePlugins() {
/**
* Running user-land plugins
*/
this.#plugins
.filter(({ options, executed }) => {
if (options && options.recurring) {
Expand All @@ -139,11 +152,30 @@ export class Edge {
plugin.fn(this, !plugin.executed, plugin.options)
plugin.executed = true
})

/**
* Running bundled plugins after the user-land
* plugins
*/
this.#bundledPlugins
.filter(({ options, executed }) => {
if (options && options.recurring) {
return true
}
return !executed
})
.forEach((plugin) => {
plugin.fn(this, !plugin.executed, plugin.options)
plugin.executed = true
})
}

/**
* Register a plugin. Plugin functions are called once just before
* an attempt to render a view is made.
* Register a plugin. Plugins are called only once just before
* a rendering a view.
*
* You can invoke a plugin multiple times by marking it as a
* recurring plugin
*/
use<T extends any>(pluginFn: PluginFn<T>, options?: T): this {
this.#plugins.push({
Expand Down

0 comments on commit f577463

Please sign in to comment.