examples/HTML StarterKit/lib/durandal/js/plugins/observable.js
function convertProperty(obj, propertyName, original){
        var observable,
            isArray,
            lookup = obj.__observable__ || (obj.__observable__ = {});

        if(original === undefined){
            original = obj[propertyName];
        }

        if (system.isArray(original)) {
            observable = ko.observableArray(original);
            makeObservableArray(original, observable);
            isArray = true;
        } else if (typeof original == "function") {
            if(ko.isObservable(original)){
                observable = original;
            }else{
                return null;
            }
        } else if(system.isPromise(original)) {
            observable = ko.observable();

            original.then(function (result) {
                if(system.isArray(result)) {
                    var oa = ko.observableArray(result);
                    makeObservableArray(result, oa);
                    result = oa;
                }

                observable(result);
            });
        } else {
            observable = ko.observable(original);
            convertObject(original);
        }

        Object.defineProperty(obj, propertyName, {
            configurable: true,
            enumerable: true,
            get: observable,
            set: ko.isWriteableObservable(observable) ? (function (newValue) {
                if (newValue && system.isPromise(newValue)) {
                    newValue.then(function (result) {
                        innerSetter(observable, result, system.isArray(result));
                    });
                } else {
                    innerSetter(observable, newValue, isArray);
                }
            }) : undefined
        });

        lookup[propertyName] = observable;
        return observable;
    }
function convertProperty(obj, propertyName, original){
        var observable,
            isArray,
            lookup = obj.__observable__ || (obj.__observable__ = {});

        if(original === undefined){
            original = obj[propertyName];
        }

        if (system.isArray(original)) {
            observable = ko.observableArray(original);
            makeObservableArray(original, observable);
            isArray = true;
        } else if (typeof original == "function") {
            if(ko.isObservable(original)){
                observable = original;
            }else{
                return null;
            }
        } else if(system.isPromise(original)) {
            observable = ko.observable();

            original.then(function (result) {
                if(system.isArray(result)) {
                    var oa = ko.observableArray(result);
                    makeObservableArray(result, oa);
                    result = oa;
                }

                observable(result);
            });
        } else {
            observable = ko.observable(original);
            convertObject(original);
        }

        Object.defineProperty(obj, propertyName, {
            configurable: true,
            enumerable: true,
            get: observable,
            set: ko.isWriteableObservable(observable) ? (function (newValue) {
                if (newValue && system.isPromise(newValue)) {
                    newValue.then(function (result) {
                        innerSetter(observable, result, system.isArray(result));
                    });
                } else {
                    innerSetter(observable, newValue, isArray);
                }
            }) : undefined
        });

        lookup[propertyName] = observable;
        return observable;
    }
function convertProperty ( obj , propertyName , original ) { var observable , isArray , lookup = obj . __observable__ || ( obj . __observable__ = { } ) ; if ( original === undefined ) { original = obj [ propertyName ] ; } if ( system . isArray ( original ) ) { observable = ko . observableArray ( original ) ; makeObservableArray ( original , observable ) ; isArray = true ; } else if ( typeof original == "function" ) { if ( ko . isObservable ( original ) ) { observable = original ; } else { return null ; } } else if ( system . isPromise ( original ) ) { observable = ko . observable ( ) ; original . then ( function ( result ) { if ( system . isArray ( result ) ) { var oa = ko . observableArray ( result ) ; makeObservableArray ( result , oa ) ; result = oa ; } observable ( result ) ; } ) ; } else { observable = ko . observable ( original ) ; convertObject ( original ) ; } Object . defineProperty ( obj , propertyName , { configurable : true , enumerable : true , get : observable , set : ko . isWriteableObservable ( observable ) ? ( function ( newValue ) { if ( newValue && system . isPromise ( newValue ) ) { newValue . then ( function ( result ) { innerSetter ( observable , result , system . isArray ( result ) ) ; } ) ; } else { innerSetter ( observable , newValue , isArray ) ; } } ) : undefined } ) ; lookup [ propertyName ] = observable ; return observable ; }
Converts a normal property into an observable property using ES5 getters and setters.
@method convertProperty
@param {object} obj The target object on which the property to convert lives.
@param {string} propertyName The name of the property to convert.
@param {object} [original] The original value of the property. If not specified, it will be retrieved from the object.
@return {KnockoutObservable} The underlying observable.
Converts a normal property into an observable property using ES5 getters and setters .