-
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.
feat(core): added try... hooks and made init/destroy universal (#66)
* feat(core): added try... hooks and made init/destroy universal * refactor(core): move options from component's context to 3rd argument
- Loading branch information
Showing
16 changed files
with
313 additions
and
79 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
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 |
---|---|---|
@@ -1,17 +1,24 @@ | ||
import { injectModuleContext } from '@/core'; | ||
import { injectComponentContext, injectModuleContext } from '@/core'; | ||
import { Logger } from '@/errors'; | ||
import { getNoContextWarning } from '@/utils'; | ||
|
||
const logger = new Logger('onDestroy'); | ||
|
||
export function onDestroy(cb: () => void) { | ||
const instance = injectModuleContext(true); | ||
export function onDestroy(cb: () => void, silent = false) { | ||
const moduleInstance = injectModuleContext(true); | ||
const componentInstance = injectComponentContext(true); | ||
|
||
if (!instance) { | ||
logger.warn(getNoContextWarning('onDestroy')); | ||
if (!moduleInstance && !componentInstance) { | ||
if (!silent) logger.warn(getNoContextWarning('onDestroy')); | ||
|
||
return; | ||
} | ||
|
||
instance.destroyBus.on(cb); | ||
const bus = moduleInstance?.destroyBus || componentInstance?.unmountBus; | ||
|
||
bus?.on(cb); | ||
} | ||
|
||
export function tryOnDestroy(cb: () => void) { | ||
onDestroy(cb, true); | ||
} |
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 |
---|---|---|
@@ -1,17 +1,24 @@ | ||
import { injectModuleContext } from '@/core'; | ||
import { injectComponentContext, injectModuleContext } from '@/core'; | ||
import { Logger } from '@/errors'; | ||
import { getNoContextWarning } from '@/utils'; | ||
|
||
const logger = new Logger('onInit'); | ||
|
||
export function onInit(cb: () => void) { | ||
const instance = injectModuleContext(true); | ||
export function onInit(cb: () => void, silent = false) { | ||
const moduleInstance = injectModuleContext(true); | ||
const componentInstance = injectComponentContext(true); | ||
|
||
if (!instance) { | ||
logger.warn(getNoContextWarning('onInit')); | ||
if (!moduleInstance && !componentInstance) { | ||
if (!silent) logger.warn(getNoContextWarning('onInit')); | ||
|
||
return; | ||
} | ||
|
||
instance.initBus.on(cb); | ||
const bus = moduleInstance?.initBus || componentInstance?.mountBus; | ||
|
||
bus?.on(cb); | ||
} | ||
|
||
export function tryOnInit(cb: () => void) { | ||
onInit(cb, true); | ||
} |
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
Oops, something went wrong.