Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Allow dots in Observe keys #318

Merged
merged 2 commits into from
Mar 16, 2013
Merged

Allow dots in Observe keys #318

merged 2 commits into from
Mar 16, 2013

Conversation

daffl
Copy link
Contributor

@daffl daffl commented Mar 15, 2013

I already merged this fix into the 1.2 develop branch with #309 but suggest to make this part of the 1.1.5 release as well. All tests are still passing and it doesn't introduce a new API. The fix makes this possible:

var ob = new can.Observe();

ob.attr('a.b', 'test');
ob.attr() // -> { a: { b: 'test' } }

ob.attr({
    'a.b': 'test'
});

ob.attr() // -> { 'a.b': 'test' }

ob.attr('a.b')
// will look for 'a.b' first
// and then for ob.attr('a').attr('b')

Since new Observe({ 'test.key': 'value' }) failed before, introducing the direct key lookup for obsreve.attr('test.key') (and falling back to the nested property lookup if it doesnt' exist) shouldn't pose a problem for any existing functionality. Fixes #257 and #296.

daffl added a commit that referenced this pull request Mar 16, 2013
@daffl daffl merged commit 7b869db into master Mar 16, 2013
@daffl daffl deleted the observe-dot-key-257-296 branch March 16, 2013 16:29
@schovi
Copy link
Contributor

schovi commented Mar 27, 2013

Having issue with set dotted key

Your example

var ob = new can.Observe();

ob.attr('a.b', 'test');
ob.attr() // -> { a: { b: 'test' } }

Throw me classic old error "can.Observe: Object does not exist"

http://jsfiddle.net/schovi/zTF9s/

Read works fine

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

Successfully merging this pull request may close these issues.

Any model with a "." in the key name will cause observe.js _set() to throw and error
2 participants