Hi Elias, Hi Zlatko,

thanks for the leading suggestions. I really appreciate your help.
I think the new decorator @InAndOut is ready.

"use strict";

import {EventEmitter} from "angular2/core";
import {Output,Input} from "angular2/core";

export function InAndOut(target:any, name:any) {

    ///// CREATE EMITTER FOR PROPERTY /////

    // emitter
    var _emitter = new EventEmitter();
    // Create new emitter property
    Object.defineProperty(target, name + "Change", {
        value: _emitter,
        enumerable: true,
        configurable: true
    });
    // create @Output decorator for the emitter
    Output()(target, name + "Change");


    ///// CREATE GETTER UND SETTER FOR PROPERTY /////

    var descriptor:PropertyDescriptor = Object.getOwnPropertyDescriptor(target, 
name);
    if (descriptor) {

        // handle an previous descriptor (getter and setter)
        Object.defineProperty(target, name, {
            get: function ():any {
                return descriptor.get.call(this);
            },
            set: function (newValue:any) {
                descriptor.set.call(this, newValue);
                // emit
                this[name + "Change"].emit(descriptor.get.call(this));
            },
            enumerable: true,
            configurable: true
        });

    } else {

        // first descriptor
        // store property value
        var _val:any;
        // Create new property
        Object.defineProperty(target, name, {
            get: function ():any {
                return _val;
            },
            set: function (newValue:any) {
                _val = newValue;
                // emit
                _emitter.emit(newValue);
            },
            enumerable: true,
            configurable: true
        });

    }
    // create @Input decorator
    Input()(target, name);


}



All my tests seem to run smoothly. 
So, I still ask myself:

*Why is an similiar **decorator **like @InAndOut not part of the angular 2? 
Is there a good reason?*

I remember I read in an article, that there was a lot of discussions about 
two-way-bindind, but I didnt get into this topic.

Regards,

Jan








Am Freitag, 6. Mai 2016 16:45:15 UTC+2 schrieb JM:
>
> Hi Elias,
>
> thanks for your suggestion. Your right, it seems the logic way. 
>
>
> Output(target, name);
>
>
>
> But it seems like you can not call the decorator function Output() 
> directly.
> I get error-messages:
>
> IDE says: "Invalid number of argument, expected 0...1"
> compiler says: " error TS2346: Supplied parameters do not match any 
> signature of call target. " 
>
> Maybe cause its part of an DecoratorFactory?
>
> So I still stuck with:
>
>     // create @Output decorator for the emitter
>     Reflect["decorate"]([
>         Output()
>     ], target, name + "Change");
>
>
> Regards,
>
> Jan
>
>
>
> Am Freitag, 6. Mai 2016 08:36:54 UTC+2 schrieb Sander Elias:
>>
>> Hi Jan,
>>
>> As you are already in a decorator, do you really need the call to 
>> reflect.decorate at all?
>> I would have gone for:
>>
>> output(target, name+'Change') 
>>
>> But as I'm not that experienced with NG2, that might be a shortcut that 
>> has unexpected features ;)
>>
>> 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