storkCore

Check-in [5d7f54f364]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Model properties that are marked to be cloned work right. Also modified objectCopy() and clone() to react better if an undefined or null object is passed. In both cases the undefined or null is simply returned.
Timelines: family | ancestors | descendants | both | clonedModelProps
Files: files | file ages | folders
SHA1:5d7f54f36409d3cfb33a8e138edad3d59b0a57a8
User & Date: setok 2018-02-06 11:16:56
Context
2018-02-06
12:28
(no comment) Leaf check-in: acabda570e user: setok tags: trunk
11:16
Model properties that are marked to be cloned work right. Also modified objectCopy() and clone() to react better if an undefined or null object is passed. In both cases the undefined or null is simply returned. Leaf check-in: 5d7f54f364 user: setok tags: clonedModelProps
10:35
Create new branch named "clonedModelProps" check-in: fb079b9d93 user: setok tags: clonedModelProps
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to examples/clonedListModel.html.

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    <li id="item_#n"><span id="text_#n"></span></li>
  </ul>
</div>        


<hr>
<address></address>
<!-- hhmts start -->Last modified: Tue Feb  6 12:33:19 EET 2018 <!-- hhmts end -->
</body>
<script type="text/javascript">
var firstList = clone(ListController);
firstList.setListContainer(elementByID("list1"));

var listItem = clone(ListItemController);
listItem.setItemTemplate(elementByID("item_#n"));







|







36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    <li id="item_#n"><span id="text_#n"></span></li>
  </ul>
</div>        


<hr>
<address></address>
<!-- hhmts start -->Last modified: Tue Feb  6 13:15:47 EET 2018 <!-- hhmts end -->
</body>
<script type="text/javascript">
var firstList = clone(ListController);
firstList.setListContainer(elementByID("list1"));

var listItem = clone(ListItemController);
listItem.setItemTemplate(elementByID("item_#n"));

Changes to storkCore.js.

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
..
71
72
73
74
75
76
77




78
79
80
81
82
83
84
...
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
...
516
517
518
519
520
521
522




523
524
525
526
527
528
529
530
531
532
533
534
535

536
537
538
539
540
541
542
...
930
931
932
933
934
935
936




















937
938
939
940
941
942
943
            proto = object.constructor.prototype;
        }
    }
    else {
        proto = Object.getPrototypeOf(object);
    }
    return proto;
}

/**
 *
 * A clone of an object is an empty object
 * with a prototype reference to the original.
 *
 * For StorkCore we're using an OO model like Self, where there are no
................................................................................
 *
 * @param {Object} obj
 *      the object to be cloned
 * @return {Object}
 *      the cloned object
 */
function clone(obj) {




    // a private constructor, used only by this one clone.
    function Clone() {
        this._base = obj;
        //console.info("object: %s", obj);
    }

    Clone.prototype = obj;
................................................................................
    };
})();

function logError(error) {
    if(window.console && window.console.error) {
        window.console.error(error);
    }
}

/**
 * Similar to document.getElementByID, but throws an error if not found.
 */

function elementByID(id) {
    var element = document.getElementById(id);
    if (element == undefined) {
        throw "Element '" + id + "' could not be found";
    } else {
        return element;
    }
}


/**
 * Search through element and its children to find the element with 'id' and
 * return it.
 */

................................................................................
/**
 * Returns a copy of the object, by creating a new object and copying
 * each property and returning the new object. This does not do a deep
 * copy. Any objects properties point to are not copied, just the references
 */
function objectCopy(source) {
    var ob;





    if (source instanceof Array) {
        ob = [];
    } else {
        ob = {};
    }

    for (var key in source) {
        ob[key] = source[key];
    }

    return ob;
}


function emptyElement(element) {
    //    children = element.childNodes;
    if(isString(element)) {
        element = elementByID(element);
    }
    if(!element || !element.hasChildNodes()) {
................................................................................
    if (this.modelProperties[key] != undefined) {
        return true;
    } else {
        return false;
    }
};






















/**
 * @protected
 * calls all the listeners for the model properties value change. The listeners
 * should have a method named "propertyChangeEvent" which receives parameters
 *  (model, property, oldvalue, newValue)
 *







|







 







>
>
>
>







 







|












|







 







>
>
>
>












|
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
..
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
...
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
...
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
...
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
            proto = object.constructor.prototype;
        }
    }
    else {
        proto = Object.getPrototypeOf(object);
    }
    return proto;
};

/**
 *
 * A clone of an object is an empty object
 * with a prototype reference to the original.
 *
 * For StorkCore we're using an OO model like Self, where there are no
................................................................................
 *
 * @param {Object} obj
 *      the object to be cloned
 * @return {Object}
 *      the cloned object
 */
function clone(obj) {
    if ( (obj === undefined) || (obj === null) ) {
        return obj;
    }

    // a private constructor, used only by this one clone.
    function Clone() {
        this._base = obj;
        //console.info("object: %s", obj);
    }

    Clone.prototype = obj;
................................................................................
    };
})();

function logError(error) {
    if(window.console && window.console.error) {
        window.console.error(error);
    }
};

/**
 * Similar to document.getElementByID, but throws an error if not found.
 */

function elementByID(id) {
    var element = document.getElementById(id);
    if (element == undefined) {
        throw "Element '" + id + "' could not be found";
    } else {
        return element;
    }
};


/**
 * Search through element and its children to find the element with 'id' and
 * return it.
 */

................................................................................
/**
 * Returns a copy of the object, by creating a new object and copying
 * each property and returning the new object. This does not do a deep
 * copy. Any objects properties point to are not copied, just the references
 */
function objectCopy(source) {
    var ob;

    if ( (source === undefined) || (source === null) ) {
        return source;
    }

    if (source instanceof Array) {
        ob = [];
    } else {
        ob = {};
    }

    for (var key in source) {
        ob[key] = source[key];
    }

    return ob;
};


function emptyElement(element) {
    //    children = element.childNodes;
    if(isString(element)) {
        element = elementByID(element);
    }
    if(!element || !element.hasChildNodes()) {
................................................................................
    if (this.modelProperties[key] != undefined) {
        return true;
    } else {
        return false;
    }
};


StorkModel.cloned = function() {
    var i, property;

    this.superMethod(StorkModel.cloned, "cloned");
    //this.listeners = objectCopy(this.listeners);
    //this.copyProperties = objectCopy(this.copyProperties);
    for (i = 0; i < this.copyProperties.length; i++) {
        property = this.copyProperties[i];
        this.modelProperties[property] = 
            objectCopy(this.modelProperties[property]);
    }

    //this.cloneProperties = objectCopy(this.cloneProperties);
    for (i=0; i < this.cloneProperties.length; i++) {
        property = this.cloneProperties[i];
        this.modelProperties[property] = clone(this.modelProperties[property]);
    }
};


/**
 * @protected
 * calls all the listeners for the model properties value change. The listeners
 * should have a method named "propertyChangeEvent" which receives parameters
 *  (model, property, oldvalue, newValue)
 *