Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Observable listener in can.Construct

$
0
0
Hi there,

I have a can.Contruct that I use as a super class, everything is fine except for the observable listener is not firing:

'{productsObservable} product': function () {
    this.activate();
},

The full can.Contruct code

  1. (function () {
        'use strict';
        var HwHellorbotBaseProductCont = can.Construct.extend(
        {
            setup: function (element, options) {
                this.element = $(element);
                this.options = can.extend({},
                                      this.constructor.defaults,
                                      options
                                     );
                return [this.element, this.options];
            },

            init: function (element, options) {
                var self = this;

                this.activate();
                // This is fine
                this.options.productsObservable.bind('product', function (ev, newVal, oldVal) {
                    self.activate();
                });
            },
            // This form of observable listener is not firing 
            '{productsObservable} product': function () {
                this.activate();
            },

            activate: function () {
                if (this.options.val === this.options.productsObservable.attr(this.options.pub)) {
                    this.render('transition.slideLeftIn', 1500);
                }
                else {
                    this.render('transition.slideRightOut', 200);
                }
            },

            render: function (anim, duration) {
                this.element.velocity(anim, { duration: duration, easing: 'easeInCubic' });
            }
        });

        window.HwHellorbotBaseProductCont = HwHellorbotBaseProductCont;
    })();

What did I do wrong?

Rog

Viewing all articles
Browse latest Browse all 3491

Trending Articles