Comments (2)
This issue has been fixed by this commit.
from ngrx-actions.
function Selector(fn: () => string) {
return function (target, propertyKey: string, descriptor: PropertyDescriptor) {
console.log(fn.bind(target)());
}
}
class Foo {
@Selector(() => {
return this.fn();
})
bar: string;
fn() {
return "hello";
}
}
transpiles to:
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var _this = this;
function Selector(fn) {
return function (target, propertyKey, descriptor) {
console.log(fn.bind(target)());
};
}
var Foo = /** @class */ (function () {
function Foo() {
}
Foo.prototype.fn = function () {
return "hello";
};
__decorate([
Selector(function () {
return _this.fn();
})
], Foo.prototype, "bar", void 0);
return Foo;
}());
You can notice that this
becomes a _this
that is not the object reference.
That's because the decorator is invoked at "class definition" time.
If you want to achieve your purpose you should do something like this:
function Selector(fn: () => string) {
return function (target, propertyKey: string, descriptor: PropertyDescriptor) {
console.log(fn.bind(target)());
}
}
class Foo {
@Selector(function(){
return this.fn();
})
bar: string;
fn() {
return "hello";
}
}
Note the normal function
instead of the =>
arrow function.
from ngrx-actions.
Related Issues (20)
- Action options HOT 1
- Store DI
- Example Stored + Entity HOT 3
- Return Store initial state to be used in the tests
- Can it be used with redux? HOT 1
- New @Effect decorator HOT 3
- @Action - samples in the README and articles are incorrect?
- NgrxActionsModule.forFeature - not working?
- @Dispatch
- Question: Unit testing with the @Select decorator
- RxJs 6 - Property 'pipe' does not exist in type 'Actions<Action>' HOT 1
- feat: support angular v6
- Question: any ETA for a ng6 compatible version? HOT 5
- Cannot find module 'ngrx-actions' HOT 8
- NgrxActionsModule nested reducers
- Publish 4.0.1 to NPM?
- Unexpected state mutation in reducers
- @Effect() decorator does not work HOT 1
- NGRX 7.x Upgrade HOT 2
- PLEASE DELETE. CREATED BY MISTAKE :D
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 ngrx-actions.