Netflix / falcor-router

A Falcor JavaScript DataSource which creates a Virtual JSON Graph document on your app server.
http://netflix.github.io/falcor
Apache License 2.0
104 stars 46 forks source link

"route: ['foo', 'bar', '{integers}']" doesn't match but "route: 'foo.bar[{integers}]'" does?!? #187

Closed jhamlet closed 7 years ago

jhamlet commented 7 years ago

@jhusain, @trxcllnt, @michaelbpaulson

Ran in to some confusing behavior in defining routes today.

Apparently the special path segments '{integers}' '{ranges}' and '{keys}' are only available in routes given as Strings.

Is this intended, or did I miss something with how to define routes as arrays?

This does not work: ['foo', 'bar', '{integers}'] but this does work 'foo.bar[{integers}]'


Thanks,

;-j

jhusain commented 7 years ago

You're correct. We may provide a way to specify these with the Array syntax in the future. Before we do that though, we have to reserve some of the key space explicitly so that we do not conflict with keys included in the domain model by users. We're considering how to do this now.

jhamlet commented 7 years ago

Yeah. Figured that out. Once I switched to using strings everything worked.

The main reason I wanted to use arrays was to have access to the path as an array in the execution of the various get/set/call methods of the route object and slice/dice/julian it for returning path-values/jsonGraphs.

However, I came to realize (with judicious uses of JSON.stringify) that falcor-router is mutating my router's route property. The router replaces my string value with the equivalent array of ['foo', 'bar', { type: 'integers', named: false }, { type: 'keys', named: false }] so I can still slice off the base part and use it in my handlers.

Very un-intuitive (and shame on you for mutating my object), but the result is the same.


;-j