Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Subclasses of $.Observe are not applied to attribute values #145

Open
jeffrose opened this issue Oct 22, 2012 · 2 comments
Open

Subclasses of $.Observe are not applied to attribute values #145

jeffrose opened this issue Oct 22, 2012 · 2 comments

Comments

@jeffrose
Copy link

When you set attribute values in a subclass of $.Observe, $.Observe is applied to those values, not the subclass.

var
    // Subclass $.Observe to add functionality
    MyObserve = $.Observe( {
        myMethod: function(){
            console.log( 'myMethod' );
        }
    } ),

    // Create an instance of my subclass
    mo = new MyObserve( {} );

mo.myMethod(); //--> 'myMethod'

mo.attr( 'foo', { foo: { bar: { qux: 'baz' } } } );

// mo.attr( 'foo' ) is $.Observe not MyObserve
mo.attr( 'foo' ).myMethod(); // ERROR

Glancing through can.Observe, it looks like this is an issue in CanJS as well.

@daffl
Copy link
Contributor

daffl commented Oct 22, 2012

I don't see what's wrong with that. If you have, for example a Person observe you don't want the address to get converted to a Person but you probably want to have observable attributes:

var Person = can.Observe({
    getAddress : function() {
        return this.attr('address');
    }
});

var inst = new Person({
    name : 'David'
});

inst.attr('address', {
    city : 'Calgary',
    country : 'Canada'
});

In the latests CanJS you can use the can.Observe.attributes plugin to convert to the Observe type you need.

@jeffrose
Copy link
Author

jeffrose commented Nov 5, 2012

While I think your use case is valid, I am not convinced that mine is not. I am essentially talking about making changes to $.Observe before extending it to a domain object.

I am not familiar enough CanJS to know how to implement it using can.Observe.attributes. I am waiting for this issue to be fixed before migrating from jQueryMX.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants