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 definition of nested model relationships with dotted notation #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gsxdsm
Copy link

@gsxdsm gsxdsm commented Aug 13, 2012

Allow definition of nested model relationships with dotted notation:

obj.model.set({person:{name:'John Doe'}})
can now be addressed with 'person.name' in data bindings as well as
obj.model.get('person.name')

Events are also specified with dotted notation
'change:person.name':function(){}

gsxdsm added 2 commits August 12, 2012 19:54
Allow definition of nested model relationships with dotted notation:

obj.model.set({person:{name:'John Doe'}})
can now be addressed with 'person.name' in data bindings as well as
obj.model.get('person.name')

Events are also specified with dotted notation
'change:person.name':function(){}
if (typeof arg === 'string') {
return this.model._data[arg];
if (typeof arg === 'string') {
var paths = arg.split('.');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, we seem to have some indentation issues here - perhaps you're using tabs and not spaces? we use spaces in Agility

@arturadib
Copy link
Owner

This looks good to me, really like those tests. @tristanls ?

@@ -343,6 +343,37 @@
this.model._data = $.extend({}, arg); // erases previous model attributes without pointing to object
}
else {
//iterate through properties and find nested declarations
for (var prop in arg){
if (prop.indexOf('.') > -1){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems that this would allow setting a property referenced by an empty string:

data-bind=".oops"

which will try to generate a structure of:

model._data[ '' ] = { oops : 'value' };

This is not a bad thing in itself, and perhaps some future convention can have special meaning for variables ".myFoo" as a result of that, just thinking out loud here.

@tristanls
Copy link
Collaborator

Made a note on code and I'm rusty getting back to ui development, but taking a quick look nothing breaking jumped out.

@golgote
Copy link

golgote commented Nov 4, 2012

What about 'person.addresses.0.street', 'person.addresses.1.street' ?
Or better 'person.addresses[0].street' ?
Maybe something like this too : this.model.get('person.addresses.$.street'), to get all streets for example ?
This can be useful as well, what do you think ?

PS: I'm just starting with Agilityjs. I've tested Backbonejs, Knockoutjs, Angularjs, Emberjs, but Agilityjs is the one that fits my way of programming the best. It's really a clever piece of code, thanks Artur. I hope that you will find more time to take care of it.

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.

None yet

4 participants