Wiring the switchValue on the substitution component

16 views
Skip to first unread message

jlmi...@kahalawai.com

unread,
Feb 18, 2014, 1:56:39 AM2/18/14
to mont...@googlegroups.com
Hi,

Struggling with another seemingly easy one...

Looking at the example:

"substitution": {
    "prototype": "montage/ui/substitution.reel",
    "properties": {
        "element": {"#": "substitution"},
        "switchValue": "profile"
    }
}

How do I wire "switchValue" to a variable in the reel's javascript file?  I've seemed to have tried every permutation I could think of but none of it seems to work for me?

Thanks in advance!

Benoit Marchant

unread,
Feb 18, 2014, 3:03:44 AM2/18/14
to jlmi...@kahalawai.com, mont...@googlegroups.com
Johnny,

The instance of the component loading the template, the instance off the prototype defined in the JavaScript file of the reel, is available as the "owner". So if in your component you have a property named "layerType" for example, the bindings section of your substitution you would do:

        "bindings": {
            "switchValue": {"<-": "@owner.layerType"}
        }


Benoit
--
You received this message because you are subscribed to the Google Groups "Montage JS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to montagejs+...@googlegroups.com.
Visit this group at http://groups.google.com/group/montagejs.
For more options, visit https://groups.google.com/groups/opt_out.

jlmi...@kahalawai.com

unread,
Feb 18, 2014, 6:45:09 PM2/18/14
to mont...@googlegroups.com, jlmi...@kahalawai.com
Hi Benoit,

I could have sworn I had tried that.  Anyway, stumbling along...

in the javascript file I have something like this:

    handleActionLinkAction: {
        value: function(evt) {
            if(this._layerType == "profile") {
                this._layerType = "contact";
            } else {
                this._layerType = "profile";
            }
        }
    },

    _layerType: {
        value: null
    },

    layerType: {

        get: function() {
            if(this._layerType == null) {
                this._layerType = "profile";
            }
            return this._layerType;
        },

        set: function(value) {
            this._layerType = value;
        }

    }

When I press the link I see that _layerType gets changed but why doesn't the substitution component switch between panels?

François Frisch

unread,
Feb 18, 2014, 6:46:55 PM2/18/14
to jlmi...@kahalawai.com, mont...@googlegroups.com
You will need to use the setter rather than assigning the underlying property. for example: this.layerType = "contact"

jlmi...@kahalawai.com

unread,
Feb 18, 2014, 7:03:16 PM2/18/14
to mont...@googlegroups.com, jlmi...@kahalawai.com
I'm missing it...

    handleActionLinkAction: {
        value: function(evt) {
            if(! this._layerType || this._layerType == "profile") {
                this.layerType.set("contact");
            } else {
                this.layerType.set("profile");
            }
        }
    },

returns a reference error can't find variable: layerType

Kris Kowal

unread,
Feb 18, 2014, 7:07:11 PM2/18/14
to mont...@googlegroups.com
+list

---------- Forwarded message ----------
From: Kris Kowal <kris....@cixar.com>
Date: Tue, Feb 18, 2014 at 4:06 PM
Subject: Re: [montagejs] Wiring the switchValue on the substitution component
To: jlmi...@kahalawai.com


Assign directly to the property. The set method is for the property descriptor. You do not call it directly.

    handleActionLinkAction: {
        value: function(evt) {
            if(this._layerType == "profile") {
                this.layerType = "contact";
            } else {
                this.layerType = "profile";
            }
        }
    },

jlmi...@kahalawai.com

unread,
Feb 18, 2014, 7:14:41 PM2/18/14
to mont...@googlegroups.com, kris....@cixar.com
Thank you.  I see it now.

Mike Czepiel

unread,
Feb 18, 2014, 7:16:01 PM2/18/14
to Jonathan Miller, mont...@googlegroups.com, Kris Kowal
This example might be illustrative, using bindings to put data where you expect.



Reply all
Reply to author
Forward
0 new messages