cloudnc / ngx-observable-lifecycle Goto Github PK
View Code? Open in Web Editor NEWLibrary for observing the lifecycle of an (ivy compiled) angular component
License: MIT License
Library for observing the lifecycle of an (ivy compiled) angular component
License: MIT License
Hi, I really like the ide of your automaticUnsubscribe
, I've already added your lib to 2 of our projects and created a takeUntilDestroy(this)
function based on yours but I had to do it two times.
We used to do this:
export class Component implements OnDestroy{
private readonly onDestroy$ = new Subject<void>();
constructor(private readonly route: ActivatedRoute){
this.route.data.pipe(takeUntil(this.onDestroy$).subscribe();
}
ngOnDestroy(){
this.onDestroy$.next();
this.onDestroy$.complete();
}
}
I believe this is common - we take it from the material repository - and based on this the takeUntilDestroy
operator name sound better than automaticUnsubscribe
, and will popup when people strat to write takeUntil
Thank you
Oddly when I setup the ngOnDestroy method in the ngOnInit method it won't work:
ngOnInit() {
const {ngOnDestroy} = getObservableLifecycle(this);
interval(400)
.pipe(
takeUntil(ngOnDestroy),
)
.subscribe(() => {
console.log('interval');
}
);
}
==> output: continued 'interval', also when component is destroyed
When I put this exact code in the constructor of the component, the console.logging will stop when the component is destroyed.
Experienced in Angular 13. ngx-observable-lifecycle: 2.1.3
master
branch failed. π¨I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.
You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. Iβm sure you can resolve this πͺ.
Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.
Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master
branch. You can also manually restart the failed CI job that runs semantic-release.
If you are not sure how to resolve this, here is some links that can help you:
If those donβt help, or if this issue is reporting something you think isnβt right, you can always ask the humans behind semantic-release.
The npm token configured in the NPM_TOKEN
environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/
.
If you are using Two-Factor Authentication, make configure the auth-only
level is supported. semantic-release cannot publish with the default auth-and-writes
level.
Please make sure to set the NPM_TOKEN
environment variable in your CI with the exact value of the npm token.
Good luck with your project β¨
Your semantic-release bot π¦π
I just noticed that within one of our internal tests on a component where we use takeUntilDestroyed
(which behind the scenes uses ngx-observable-lifecycle
), we get the following error when we want to assert that the component creation fails:
at Object.takeUntilDestroyed (../core/browser/src/lib/lifecycle/lifecycle.ts:11:11)
console.error
Error during cleanup of component {
component: HostComponent {
__ngContext__: LRootView [
null,
[TView],
666,
null,
null,
null,
null,
null,
[Object],
[Object],
[AnimationRendererFactory],
[BaseAnimationRenderer],
null,
[LComponentView_HostComponent],
[LComponentView_HostComponent],
null,
[Circular],
null,
0,
null,
[LComponentView_HostComponent],
0,
0,
0,
0,
0,
0,
0,
0,
-1,
[Circular]
]
},
stacktrace: TypeError: Cannot read property 'ngOnDestroy' of undefined
at CuiButton.proto.<computed> (/home/maxime/Documents/my-project/ngx-observable-lifecycle/src/lib/ngx-observable-lifecycle.ts:60:24)
Here's the test that we're running:
it.only('should throw error when href property applied to non-link button', () => {
expect(() => createHost(`<cui-button type="button" href="http://example.com/">Click me</cui-button>`)).toThrow();
});
I've tried to replicate this within a test on this repo unfortunately no luck, maybe I didn't do exactly what Spectator is doing behind the scenes π€.
I've tried to play a bit with the compiled code directly on the project and if I replace
with
originalOnDestroy?.call(componentInstance);
it seems to work. I'm not 100% sure it's the correct fix though.
But my guess is even if the creation of the component fails (could be on the first CD pass actually?) some subscriptions may already be open and we would still want to clean them up? I'm having a hard time figure out exactly what's going on during the creation of a component failing π
If you have any idea let me know, happy to make a PR but I gave a go and didn't go super far
When trying this library within an Angular 10 project I get this error on the commandline:
"Error: ./node_modules/ngx-observable-lifecycle/fesm2015/ngx-observable-lifecycle.mjs 10:51-58
Can't import the named export 'Subject' from non EcmaScript module (only default export is available)"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.