Skip to content

Commit 22ddf07

Browse files
committed
Add hook useBeforeRender
1 parent 8cfbdac commit 22ddf07

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-element",
3-
"version": "0.0.228",
3+
"version": "0.0.229",
44
"description": "",
55
"license": "LGPL-3.0",
66
"main": "./index.js",

src/main/js-element-hooks.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,35 @@ export const useAfterMount = hook(
307307
}
308308
)
309309

310-
// === useBeforeUpdate ===================================================
310+
// === useBeforeRender ===============================================
311+
312+
export const useBeforeRender = hook(
313+
'useBeforeRender',
314+
function (action: () => void | undefined | null | (() => void)) {
315+
let cleanup: Task | null | undefined | void = null
316+
const c = currentCtrl!
317+
318+
const task = () => {
319+
cleanup && cleanup()
320+
cleanup = action()
321+
}
322+
323+
c.beforeMount(task)
324+
c.beforeUpdate(task)
325+
326+
c.beforeUnmount(() => {
327+
cleanup && cleanup()
328+
cleanup = null
329+
})
330+
}
331+
)
332+
333+
// === useBeforeUpdate ===============================================
311334

312335
export const useBeforeUpdate = hook(
313336
'useBeforeUpdate',
314337
function (action: () => void | undefined | null | (() => void)) {
315-
let cleanup: Task | null | undefined | void
338+
let cleanup: Task | null | undefined | void = null
316339
const c = currentCtrl!
317340

318341
c.beforeUpdate(() => {
@@ -322,6 +345,7 @@ export const useBeforeUpdate = hook(
322345

323346
c.beforeUnmount(() => {
324347
cleanup && cleanup()
348+
cleanup = null
325349
})
326350
}
327351
)

0 commit comments

Comments
 (0)