[Lift] Re: Adding / Updating a JsObj
On Mar 24, 10:27 pm, Timothy Perrett wrote: > Hey Marius, > > > 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) > > I think your exactly right - its doable, but it just feels dirty. > lol. > > > 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". > > Do you think we could add this to JsObj? There appears to be a good > rational for it. What do you think? I think you should change the List to mutable Map > > Cheers, Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Adding / Updating a JsObj
Hey Marius, > 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) I think your exactly right - its doable, but it just feels dirty. lol. > 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". Do you think we could add this to JsObj? There appears to be a good rational for it. What do you think? Cheers, Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Adding / Updating a JsObj
Tim, I'm suggest going back to using a Map. If you're having problems with Map, then you'll have problems with JsObj. Debug your Map problem and all should be good. Thanks, David On Tue, Mar 24, 2009 at 12:46 PM, Timothy Perrett wrote: > > Hmm, it seems like this is not enough as lists do not care for keys. > 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. 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. > > Thoughts? > > Cheers, Tim > > > On Mar 24, 7:10 pm, Timothy Perrett 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." 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 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 > > > -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Adding / Updating a JsObj
On Mar 24, 9:46 pm, Timothy Perrett 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 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." 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 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 liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Adding / Updating a JsObj
oops typo Perreyt = Perrett :D On Mar 24, 10:15 pm, "marius d." wrote: > On Mar 24, 9:46 pm, Timothy Perrett 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 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." 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 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 liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Adding / Updating a JsObj
Hmm, it seems like this is not enough as lists do not care for keys. 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. 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. Thoughts? Cheers, Tim On Mar 24, 7:10 pm, Timothy Perrett 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." 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 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 liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Adding / Updating a JsObj
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." 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 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 liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Adding / Updating a JsObj
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 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 liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---