File tree Expand file tree Collapse file tree 3 files changed +39
-8
lines changed Expand file tree Collapse file tree 3 files changed +39
-8
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " js-element" ,
3- "version" : " 0.0.225 " ,
3+ "version" : " 0.0.228 " ,
44 "description" : " " ,
55 "license" : " LGPL-3.0" ,
66 "main" : " ./index.js" ,
Original file line number Diff line number Diff line change @@ -309,12 +309,31 @@ export const useAfterMount = hook(
309309
310310// === useBeforeUpdate ===================================================
311311
312- export const useBeforeMount = hook (
312+ export const useBeforeUpdate = hook (
313313 'useBeforeUpdate' ,
314314 function ( action : ( ) => void | undefined | null | ( ( ) => void ) ) {
315315 let cleanup : Task | null | undefined | void
316316 const c = currentCtrl !
317317
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+
318337 c . beforeMount ( ( ) => {
319338 cleanup = action ( )
320339 } )
Original file line number Diff line number Diff line change @@ -280,7 +280,7 @@ class BaseElement extends HTMLElement {
280280 try {
281281 onceBeforeUpdateNotifier . notify ( )
282282 } finally {
283- onceBeforeMountNotifier . clear ( )
283+ onceBeforeUpdateNotifier . clear ( )
284284 }
285285
286286 beforeUpdateNotifier . notify ( )
@@ -324,6 +324,7 @@ class BaseElement extends HTMLElement {
324324 if ( ! rendered ) {
325325 addPropHandling ( this )
326326 onceBeforeMountNotifier . notify ( )
327+ onceBeforeMountNotifier . close ( )
327328 }
328329
329330 beforeMountNotifier . notify ( )
@@ -457,13 +458,24 @@ function propNameToAttrName(propName: string) {
457458}
458459
459460function createNotifier ( ) {
460- const subscribers : ( ( ) => void ) [ ] = [ ]
461+ let subscribers : ( ( ) => void ) [ ] | null = [ ]
461462
462463 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+ }
467479 }
468480}
469481
You can’t perform that action at this time.
0 commit comments