TypeError: property.put is not a function

When I try to pass dmodel properties to my widget, it fails with this error.

dojo.js:7 TypeError: property.put is not a function
at Object.set (Model.js:301)
at Object._applyAttributes (_WidgetBase.js:486)
at Object.create (_WidgetBase.js:418)
at Object.postscript (_WidgetBase.js:347)
at new (dojo.js:7)
at _CanvasFactory.create (canvasFactory.js:21)
at pageFactory.js:160
at Store.js:125
at _2f7 (dojo.js:7)
at TMP.then._304.then (dojo.js:7) "TypeError: property.put is not a function

When I remove the parameter from the constructor, the widget is created normally.

First I get my object using filter, then pass the result of the filter (the model properties) into the create function. That function instantiates a new widget.

model.header.filter({ sectionId: sectionId }).forEach(function (canvas) {
    someArray.push(that.canvasFactory().create(canvas, that.editorFunctions));
});

where model.header is

this.header = (declare([Memory]))({
    Model: jsonSchema(headerSchema),
    idProperty: "canvasId",
});
  • created using the modules
'dstore/Memory',
"dmodel/Model",
'dstore/Trackable',
'dmodel/extensions/jsonSchema',

Create function

define([ 
"modulelFolder/canvas/Header"
],


function (

    test
    ) {

    var _instance;
    function _CanvasFactory() {
    }
    
    _CanvasFactory.prototype = {

        init: function () {
            console.log("test");
        },

        create: function (modelProperties, funcs) {
            var widget = new test(modelProperties,funcs);
            return widget;
        }

    };

    return function _getSingleton() {
        if (!_instance) {
            _instance = new _CanvasFactory();
            _instance.init();
        }
        return _instance;
    };
});

And my basic template widget that gets created looks like this

define([
    "dojo/_base/declare",

    "dijit/_WidgetBase",
    "dijit/_TemplatedMixin",

    "dojo/text!./templates/Header.html",
    "dojo/text!./templates/Details.html",
    "dojo/text!./templates/Footer.html"

],

function (
    declare,

    _WidgetBase,
    _TemplatedMixin,

    template_header,
    template_details,
    template_footer

    ) {

    return declare([_WidgetBase, _TemplatedMixin], {

        canvasProperties: undefined,

        templateString: template_header,

        constructor: function (properties, funcs) {
            this.canvasProperties = properties;
        },

        postCreate: function () {
            this.inherited(arguments);
        },

        startup: function () {
        },

        destroy: function () {
            var that = this;
            this.inherited(arguments);

        }
    }

    );
});

If I don’t pass the properties to the constructor, the error goes away.
Any ideas why this is happening?

EDIT:
I isolated the part where the error occurs to this code in Model.js. But I still don’t understand why the act of passing the model properties through the constructor of the widget, is triggering set() on all the properties.

Also when I looked at the call stack, calling the constructor to create a new widget,

var widget = new test(modelProperties,funcs)

causes the following functions to execute

Capture_

EDIT:
Ok I tracked down the problem to this function in _WidgetBase

create: function(params, srcNodeRef){

So whatever I pass into the constructor of my widget if its the first and second parameter, it becomes the params, and srcNodeRef in widgetbase, and the functions that work on those parameters are working on the objects I am passing to the constructor.

Really strange design here, because I expected that the constructor would accept any initialization parameters that are needed to create the object. There is no way to do this as it is written, unless I pass them into my widget after the second parameter like this

constructor: function (params, srcNodeRef, myParam1, myParam2, etc)

and my call looks like

var widget = new test(null, null, myParam1, myParam2, …)

Is it always the first and second parameters that are reserved for special initialization functions?

Is there an alternative recommended way to get my parameters into the custom widget during construction (before postCreate) - that will not interfere with anything else??

This may be useful for something like lang.partial. But in terms of API design, there’s definitely some interesting things in how we had to make this all work for Dojo 1.x!