On Mar 24, 9:46 pm, Timothy Perrett <[email protected]> wrote:
> Hmm, it seems like this is not enough as lists do not care for keys.

A valid JSON structure allows multiple properties with the same name
such as:

var x = {
 name: "Perreyt",
 name: "Tim"
}


... guess what alert(x.name) displays :) ?

The props function returns a List[(String, JxExp)] which you can
iterate over

The +* function allows you to concatenate the props of two JsObj.

> In my use case, im actually building a library for something that
> provide default options that are inserted into a flash object. So,
> given:
>
> { key: 'value', something: 'else' }
>
> I *need* to only have one of the "something" key, as it has a bearing
> on the application. If someone wants to change / override the default
> value in there client application, this is extremely difficult - seems
> like it would need a lot of boilerplate code to convert to list, hack
> about in the list, then manually convert it back to JsObj.

Not difficult but not convenient either such as:

def update(name: String, newVal: JsExp, obj: JsObj) = (for (found <-
obj.props if found._1 != name) yield found) ::: List(name, newVal)

which return the new List ... which is suboptimal comparing with a
Map.

>Can we not
> add some support for Map[String, JsExp] and going to to/from JsObj?
> IMO, it seems like its a natural fit given the key-pair nature of
> JsObj.

Personally I'm fine with a Map[String, JxExp] instead of List because
if we have the same property multiple times in a JSON construct the
last occurrence "wins".

>
> Thoughts?
>
> Cheers, Tim
>
> On Mar 24, 7:10 pm, Timothy Perrett <[email protected]> wrote:
>
> > Hmm, I saw those methods but they are not documented so didnt know
> > what they did!
>
> > Will +* replace an object thats the same?
>
> > On Mar 24, 6:45 pm, "marius d." <[email protected]> wrote:
>
> > > Please see
>
> > > def props: List[(String,JsExp)]
>
> > > and
>
> > > def +*(other: JsObj)
>
> > > would this suffice ?
>
> > > +* looks like an awkward name to me ... ++ expresses concatenation
> > > better IMHO.
>
> > > Br's,
> > > Marius
>
> > > On Mar 24, 8:36 pm, Tim Perrett <[email protected]> wrote:
>
> > > > Hey guys,
>
> > > > So, I have a JsObj with a bunch of key-value pairs - how can I both
> > > > add new key pairs or update existing values?
>
> > > > I originally had my data being held as Map[String,String], and
> > > > attempted to convert it to JsObj however this was for some reason
> > > > causing a massive memory leak which nearly crashed my entire mac. lol.
>
> > > > Thoughts?
>
> > > > Cheers, Tim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to