kiva / backbone.siren

Converts Siren JSON representations into Backbone Models
MIT License
14 stars 3 forks source link

Provide deep linking down the entity chain #16

Closed gxxcastillo closed 11 years ago

gxxcastillo commented 11 years ago

Following up on Kevin's comments in this thread: https://github.com/kiva/backbone.siren/pull/15

...and as mentioned in this twitter thread: https://twitter.com/dhh/status/281779048978472960 and in this post: http://37signals.com/svn/posts/3373-getting-hyper-about-hypermedia-apis

We need some kind of deep linking.

I still need to figure out how to define the api for this but the idea is you should be able to do:

getSomeEntity('baseEntity#nestedEntityName#anotherNestedEntityName');

The idea behind the '#' is to be somewhat similar to css selectors. Eventually, if we want to support selecting by "class" we might want to do something like:

getSomeEntity('baseEntity.someClassName');

...just for now...yet to see how it can work out...

apsoto commented 11 years ago

I don't think multiple hashes is valid syntax.

gxxcastillo commented 11 years ago

Yeah, apologies for the misleading verbiage, while deep linking via a url hash would be invalid I was thinking of something more similar to a CSS selector. (only we are using "name" instead of "id")

gxxcastillo commented 11 years ago

I've got this mostly coded up. There are two functions:

A static function, Backbone.Siren.resolveChain() and an instance method, instance.resolveChain(). Both take a "selector" string like the one mentioned above (to avoid any confusion, I'm referring to this selector string as a "chain" from now on). Both also return a jQuery promise that resolves with the last descendant in the "chain" as the argument to all callbacks.

I'm open to ideas on better syntax for the "chains". I'm also wondering if maybe it makes sense to have the argument to all promise callbacks be the root level object as apposed to the last descendant...?

Code should be in shortly...

gxxcastillo commented 11 years ago

Closing this out. It's currently functional via `Backbone.Siren.resolve()' and while it needs additional work, I'll file that under a separate ticket.