Hi Elias,

what I have so far is.
 
 

> @Component({
>     selector: "clock",
>     template: `
> <timer [(seconds)]="seconds" [(minutes)]="minutes"></timer>
>         `
> })
> export class Clock{
>
>     @InAndOut
>     public seconds:number;
>     @Output("secondsChange") secondsChange:EventEmitter<number> = new 
> EventEmitter();
>
>
>     @InAndOut
>     public minutes:number;
>     @Output("minutesChange") minutesChange:EventEmitter<number> = new 
> EventEmitter();
>
> }
>
>

And as decorator definiton

import {EventEmitter} from "angular2/core";
>
> export function InAndOut(target:any, name:any) {
>
>     // property value
>     var _val = this[name];
>
>     // property getter
>     var getter = function () {
>         return _val;
>     };
>
>     // property setter
>     var setter = function (newVal:any) {
>         _val = newVal;
>         // emit
>         if( this[name + "Change"] ) {
>             this[name + "Change"].emit(newVal);
>         }
>     };
>
>     // Delete property.
>     if (delete this[name]) {
>
>         // Create new property with getter and setter
>         Object.defineProperty(target, name, {
>             get: getter,
>             set: setter,
>             enumerable: true,
>             configurable: true
>         });
>
>     }
>
> }
>
>
Is there a chance to include the creation of secondsChange with the @Output 
decorator from inside the @InAndOut decorator.
So I could reduce the lines:


@InAndOut public seconds:number = 0;
@Output("secondsChange") secondsChange = new EventEmitter();



to:


@InAndOut public seconds:number = 0;




Regards,

Jan



Am Mittwoch, 4. Mai 2016 08:01:59 UTC+2 schrieb Sander Elias:
>
> Hi Jan,
>
> With my limited experience of NG2, I think this is the only way. But you 
> are right, it does not feel right. This throws out DRY altogether. 
> What came to mind was writing a 'proxy' decorator, that handles all this 
> in a single line of code. However, this takes care of the symptoms, and I 
> feel I need to dig a bit deeper to see if there is a cure.
>
> Regards
> Sander
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to