Comments (13)
Hey there,
Firstly, appreciate your prompt response!
The Logging aspect works as expected. My IDE shows no errors either, however, in the browser is where i see the error.
Here is the full implementation (without @Injectable :)) -
import { AdvicePool, adviceMetadata, IMetadata } from 'kaop-ts'
export class LoggingAspect extends AdvicePool {
static log( @adviceMetadata meta: IMetadata) {
console.log('Called: ', meta.target)
console.log('Args: ', meta.args)
}
}
And the service method i am injecting it to is:
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable'
// kaop imports
import { beforeMethod } from 'kaop-ts';
import { LogAspect } from '../sample-advice';
import 'rxjs/add/operator/toPromise';
@Injectable
export class MyService {
constructor(private http: Http) { }
@beforeMethod(LoggingAspect.log)
httpGetRequest(url: string): Promise<Response> {
return this.http.get(url)
.toPromise().then(...)
}
}
I also tried the example on the readme, with the same error in the browser console:
static log( @adviceMetadata metadata: IMetadata) {
console.log(`${metadata.target.name}::${metadata.propertyKey}()`) // class and method name
console.log(`called with arguments: `)
console.log(metadata.args) // function arguments
console.log(`output a result of: `)
console.log(metadata.result) // returned value
}
(edit .. place ```javascript before a block of code to highlight :))
from kaop-ts.
Hi @musti2!
in the browser is where i see the error
How are you running it? Can you provide the exact steps in order to reproduce it? That'd help a lot
from kaop-ts.
@musti2 @k1r0s I found the issue, we can fix by changing IMetadata
to an empty class, instead of an interface.
The problem is in TypeScript + Webpack side, not in ours, but apparently it's a real issue. When exporting code + interfaces in the same file, Webpack treats it as CJS modules instead of ESM, causing compile-time code (interfaces) to be looked up. Of course this is removed after all by TypeScript, so that's why it's a warning and things keep running.
There are 2 solutions: either split exports in separate files (one for code and another for interfaces) or rewrite the exported interfaces (IMetadata) as an empty class. Keep in mind empty classes, used as types (no new
invoked) in TypeScript are removed when compiled, just as interfaces, so no junk code is generated.
More info on angular/angular-cli#2034 (comment)
from kaop-ts.
@k1r0s I think it was too early to close, since we didn't provide a final solution.
I've been investigating. As you could have seen in angular/angular-cli#2034 (comment), the issue have implications on Webpack, TypeScript and Angular, so prob the issue will remain for a time, and is not in our side. Is not too important anyway since is a warning.
Anyway, I've tried several things from kaop-ts
side, and there is nothing we can do. The best workaround I found is in the angular app re-exporting the interface from an inteface-only file (very important, don't mix interfaces with variables, const, classes or functions in that file):
// app/interfaces.ts
...
export { IMetadata } from 'kaop-ts';
...
// app/logging-aspect.ts
import { adviceMetadata, AdvicePool } from 'kaop-ts'
import { IMetadata } from './interfaces' // Import from here instead
class LoggingAspect extends AdvicePool {
static log( @adviceMetadata meta: IMetadata) {
console.log('Called: ', meta.target);
console.log('Args: ', meta.args);
}
}
That will remove the warnings.
@k1r0s I'd suggest to add this case to a Troubleshooting section in the Readme. Then is more visible for the angular users
from kaop-ts.
Thanks to @musti2! We learnt something new today
from kaop-ts.
I think you're trying to inject an instance of LogAspect somewhere. You should import LogAspect
and use LogAspect.log
directly placing it on any decorator this lib provides.
log method is 'static' so there is no need to apply 'Injectable()' :)
by the way can you please provide a gist or paste your implementation?
from kaop-ts.
export 'IMetadata' was not found in 'kaop-ts'
error is due Angular is trying to inject meta
as an instance of IMetadata which is not declared as a dependency.
to retrieve method metadata you don't need @Injectable()
from kaop-ts.
So, advice is working but u got an error anyway? :\ seems weird
Hold on, I'm gonna test this
from kaop-ts.
I think Angular nor this library is the cause of this :\ gonna seek a solution
from kaop-ts.
Enough arguments by @alexjoverm to close this, thanks mate
from kaop-ts.
Agree. Best contributor ever
from kaop-ts.
Another painless workarround
More info
angular/angular-cli#2034 (comment)
from kaop-ts.
Thanks guys! Appreciate it.
The workaround does the trick.
from kaop-ts.
Related Issues (20)
- reexport inject and provider from kaop pkg
- allow access to `...advices` throught function prop
- advice order is wrong when on stacked joinpoints [breaking changes]
- promise based decorators? HOT 6
- [docs] Chinese | Russian translation
- An in-range update of ts-jest is breaking the build 🚨 HOT 3
- An in-range update of @types/node is breaking the build 🚨 HOT 4
- The automated release is failing 🚨
- after constructor advices no longer stack HOT 1
- Function calls are not supported in decorators - Angular 7 HOT 3
- Version 4.0.0 silently changes target to es6 HOT 2
- utility to clear all decorators HOT 1
- An in-range update of rollup is breaking the build 🚨 HOT 48
- Result of advise's first execution repeating itself in following executions when running all tests HOT 4
- applyAspect not fully reading proto chain HOT 1
- Prevents + Commit HOT 3
- declaration for module 'kaop' is needed HOT 6
- Advices on functions defined as properties HOT 2
- Async advices HOT 1
- How do I apply advices to all the methods in every class/component in angular? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kaop-ts.