File tree 3 files changed +39
-8
lines changed
3 files changed +39
-8
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " js-element" ,
3
- "version" : " 0.0.225 " ,
3
+ "version" : " 0.0.228 " ,
4
4
"description" : " " ,
5
5
"license" : " LGPL-3.0" ,
6
6
"main" : " ./index.js" ,
Original file line number Diff line number Diff line change @@ -309,12 +309,31 @@ export const useAfterMount = hook(
309
309
310
310
// === useBeforeUpdate ===================================================
311
311
312
- export const useBeforeMount = hook (
312
+ export const useBeforeUpdate = hook (
313
313
'useBeforeUpdate' ,
314
314
function ( action : ( ) => void | undefined | null | ( ( ) => void ) ) {
315
315
let cleanup : Task | null | undefined | void
316
316
const c = currentCtrl !
317
317
318
+ c . beforeUpdate ( ( ) => {
319
+ cleanup && cleanup ( )
320
+ cleanup = action ( )
321
+ } )
322
+
323
+ c . beforeUnmount ( ( ) => {
324
+ cleanup && cleanup ( )
325
+ } )
326
+ }
327
+ )
328
+
329
+ // === useBeforeMount ====================================================
330
+
331
+ export const useBeforeMount = hook (
332
+ 'useBeforeMount' ,
333
+ function ( action : ( ) => void | undefined | null | ( ( ) => void ) ) {
334
+ let cleanup : Task | null | undefined | void
335
+ const c = currentCtrl !
336
+
318
337
c . beforeMount ( ( ) => {
319
338
cleanup = action ( )
320
339
} )
Original file line number Diff line number Diff line change @@ -280,7 +280,7 @@ class BaseElement extends HTMLElement {
280
280
try {
281
281
onceBeforeUpdateNotifier . notify ( )
282
282
} finally {
283
- onceBeforeMountNotifier . clear ( )
283
+ onceBeforeUpdateNotifier . clear ( )
284
284
}
285
285
286
286
beforeUpdateNotifier . notify ( )
@@ -324,6 +324,7 @@ class BaseElement extends HTMLElement {
324
324
if ( ! rendered ) {
325
325
addPropHandling ( this )
326
326
onceBeforeMountNotifier . notify ( )
327
+ onceBeforeMountNotifier . close ( )
327
328
}
328
329
329
330
beforeMountNotifier . notify ( )
@@ -457,13 +458,24 @@ function propNameToAttrName(propName: string) {
457
458
}
458
459
459
460
function createNotifier ( ) {
460
- const subscribers : ( ( ) => void ) [ ] = [ ]
461
+ let subscribers : ( ( ) => void ) [ ] | null = [ ]
461
462
462
463
return {
463
- subscribe : ( subscriber : ( ) => void ) => void subscribers . push ( subscriber ) ,
464
- notify : ( ) =>
465
- void ( subscribers . length && subscribers . forEach ( ( it ) => it ( ) ) ) ,
466
- clear : ( ) => ( subscribers . length = 0 )
464
+ subscribe ( subscriber : ( ) => void ) {
465
+ subscribers && subscribers . push ( subscriber )
466
+ } ,
467
+
468
+ notify ( ) {
469
+ subscribers && subscribers . length && subscribers . forEach ( ( it ) => it ( ) )
470
+ } ,
471
+
472
+ clear ( ) {
473
+ subscribers && ( subscribers . length = 0 )
474
+ } ,
475
+
476
+ close ( ) {
477
+ subscribers = null
478
+ }
467
479
}
468
480
}
469
481
You can’t perform that action at this time.
0 commit comments