autocomplete

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

autocomplete

sebastianconcept
Hey guys,
have you successfully used an autocomplete from amber?

When I execute this:

jQuery ajax: #{ 
'url' -> 'http://ws.geonames.org/searchJSON'.
'dataType' -> 'jsonp'.
'data' -> #{
'featureClass' -> 'P'.
'style' -> 'full'.
'maxRows' -> 12.
'name_startsWith' -> 'foz'}.
'success' -> [:d|console log: d]}.

I get chrome using 99% CPU to no end

That code is part of what's needed to get it working.
Js example here:
http://jqueryui.com/demos/autocomplete/#remote-jsonp

any idea?

sebastian

Reply | Threaded
Open this post in threaded view
|

Re: autocomplete

Balázs Kósi
Hi!

I tried it with firefox on the amber site.
It throws an error: [object Window] does not understand #keys.

I was also able to go into the infinite loop, by calling jQuery.ajax
with the HashedCollection from the console.

I think the cause of this behaviour is that we supply a HashedCollection,
which has unnecessary properties, and jQuery.ajax maybe tries to make
a deep walk on the supplied object? not sure.

https://github.com/jquery/jquery/blob/master/src/ajax.js#L138

I have an experimental solution for this:
https://github.com/balazskosi/amber/commit/dd3f3d3543e3fe2d91d995810ec329fb492b6587

cheers, Balázs
Reply | Threaded
Open this post in threaded view
|

Re: autocomplete

Nicolas Petton
Balázs Kósi <[hidden email]> writes:

Hi!

> I have an experimental solution for this:
> https://github.com/balazskosi/amber/commit/dd3f3d3543e3fe2d91d995810ec329fb492b6587

Did you try to fully replace HashedCollection literals with your
implementation? Any side effect?

Cheers,
Nico

--
Nicolas Petton
http://nicolas-petton.fr
Reply | Threaded
Open this post in threaded view
|

Re: autocomplete

Balázs Kósi
Hi,
 
Did you try to fully replace HashedCollection literals with your
implementation? Any side effect?

This implementation replaces HashedCollection literals with the new syntax,
but it's certainly possible to have both side by side. Although I don't know what
HashedCollections offer that js objects don't. On the other hand, there is a
need to create "pure" js objects as Sebastian's example shows.
I didn't notice any side effects yet. Amber works great :)

cheers, Balázs

p.s: The ajax call above could be rewritten like this:

jQuery ajax: #{
    url: 'http://ws.geonames.org/searchJSON'.
    dataType: 'jsonp'.
    data: #{
        featureClass: 'P'.
        style: 'full'.
        maxRows: 12.
        'name_startsWith': 'foz'}.
    success: [:d | console log: d ] }
Reply | Threaded
Open this post in threaded view
|

Re: autocomplete

Nicolas Petton
Balázs Kósi <[hidden email]> writes:

Yep, keeping HashedCollection could be good idea, then we could use
plain JS objects as literals for such cases.

I'll have a deeper look at your fork!

Cheers,
Nico

> Hi,
>  
>
>     Did you try to fully replace HashedCollection literals with your
>     implementation? Any side effect?
>    
>
> This implementation replaces HashedCollection literals with the new
> syntax,
> but it's certainly possible to have both side by side. Although I don't
> know what
> HashedCollections offer that js objects don't. On the other hand,
> there is a
> need to create "pure" js objects as Sebastian's example shows.
> I didn't notice any side effects yet. Amber works great :)
>
> cheers, Balázs
>
> p.s: The ajax call above could be rewritten like this:
>
> jQuery ajax: #{
>     url: 'http://ws.geonames.org/searchJSON'.
>     dataType: 'jsonp'.
>     data: #{
>         featureClass: 'P'.
>         style: 'full'.
>         maxRows: 12.
>         'name_startsWith': 'foz'}.
>     success: [:d | console log: d ] }

--
Nicolas Petton
http://nicolas-petton.fr
Reply | Threaded
Open this post in threaded view
|

Re: autocomplete

sebastianconcept
In reply to this post by Balázs Kósi
ok.

I've merged your stuff with Nicolas edge version.

It's looking really good!

you guys rock!





Em segunda-feira, 28 de maio de 2012 13h31min01s UTC-3, Balázs escreveu:
Hi,
 
Did you try to fully replace HashedCollection literals with your
implementation? Any side effect?

This implementation replaces HashedCollection literals with the new syntax,
but it's certainly possible to have both side by side. Although I don't know what
HashedCollections offer that js objects don't. On the other hand, there is a
need to create "pure" js objects as Sebastian's example shows.
I didn't notice any side effects yet. Amber works great :)

cheers, Balázs

p.s: The ajax call above could be rewritten like this:

jQuery ajax: #{
    url: 'http://ws.geonames.org/searchJSON'.
    dataType: 'jsonp'.
    data: #{
        featureClass: 'P'.
        style: 'full'.
        maxRows: 12.
        'name_startsWith': 'foz'}.
    success: [:d | console log: d ] }
Reply | Threaded
Open this post in threaded view
|

Re: autocomplete

Herby Vojčík
In reply to this post by Balázs Kósi
Why new things? What is bad with HashedCollection? It had problems not a
long time ago, but nowadays it should only have those properties
(enumaerable) that are its keys.

Herby

Balázs Kósi wrote:

> Hi,
>
>     Did you try to fully replace HashedCollection literals with your
>     implementation? Any side effect?
>
>
> This implementation replaces HashedCollection literals with the new syntax,
> but it's certainly possible to have both side by side. Although I don't
> know what
> HashedCollections offer that js objects don't. On the other hand, there
> is a
> need to create "pure" js objects as Sebastian's example shows.
> I didn't notice any side effects yet. Amber works great :)
>
> cheers, Balázs
>
> p.s: The ajax call above could be rewritten like this:
>
> jQuery ajax: #{
> url: 'http://ws.geonames.org/searchJSON'.
> dataType: 'jsonp'.
> data: #{
> featureClass: 'P'.
> style: 'full'.
> maxRows: 12.
> 'name_startsWith': 'foz'}.
> success: [:d | console log: d ] }
Reply | Threaded
Open this post in threaded view
|

Re: autocomplete

Balázs Kósi
Hi!

On Tuesday, May 29, 2012 12:09:57 PM UTC+2, Herby wrote:
Why new things? What is bad with HashedCollection? It had problems not a
long time ago, but nowadays it should only have those properties
(enumaerable) that are its keys.
You're right. I tried the example with the latest amber from the repo, and it works,
and indeed HashedCollection has only its keys as enumerable properties, and
other smalltalk objects only their inst vars. I guess this is the relevant code:
https://github.com/NicolasPetton/amber/blob/master/js/boot.js#L145

That means that the main reason for my change is gone. There are two other
aspects to consider:

1) Syntax:

   #{ a: 1 }
   #{ 'a' -> 1 }

I think pros for the new syntax is, that it's "lighter" and resembles the js object literal syntax.

Pros for the old syntax is that it's a bit more flexible. You can write:
   k := 'foo'. #{ k -> 1 }
or even
   a := 'foo' -> 1. #{ a }

2) Performance:

n := 100000.
{
    [ #{ 'a' -> 1. 'b' -> 1. 'c' -> 1 } ].
    [ HashedCollection new at: 'a' put: 1; at: 'b' put: 1; at: 'c' put: 1; yourself ].
    [ #{ a: 1. b: 1. c: 1 } ].
    [ ] } collect: [ :each | [ n timesRepeat: each ] timeToRun ]  " #(3705 894 130 157) "

Clearly there is some optimisation to be done with the old implementation.

I like the new syntax more, and I think we should contemplate about the relation
between HashedCollection and JSObjectProxy a bit. What do you think?

cheers, Balázs
Reply | Threaded
Open this post in threaded view
|

Re: autocomplete

Herby Vojčík


Balázs Kósi wrote:

> Hi!
>
> On Tuesday, May 29, 2012 12:09:57 PM UTC+2, Herby wrote:
>
>     Why new things? What is bad with HashedCollection? It had problems
>     not a
>     long time ago, but nowadays it should only have those properties
>     (enumaerable) that are its keys.
>
> You're right. I tried the example with the latest amber from the repo,
> and it works,
> and indeed HashedCollection has only its keys as enumerable properties, and
> other smalltalk objects only their inst vars. I guess this is the
> relevant code:
> https://github.com/NicolasPetton/amber/blob/master/js/boot.js#L145
>
> That means that the main reason for my change is gone. There are two other
> aspects to consider:
>
> 1) Syntax:
>
> #{ a: 1 }
> #{ 'a' -> 1 }
>
> I think pros for the new syntax is, that it's "lighter" and resembles
> the js object literal syntax.

Resembling js syntax is not a pro (imo)! Amber is Smalltalk.

> Pros for the old syntax is that it's a bit more flexible. You can write:
> k := 'foo'. #{ k -> 1 }
> or even
> a := 'foo' -> 1. #{ a }
>
> 2) Performance:
>
> n := 100000.
> {
> [ #{ 'a' -> 1. 'b' -> 1. 'c' -> 1 } ].
> [ HashedCollection new at: 'a' put: 1; at: 'b' put: 1; at: 'c' put: 1;
> yourself ].
> [ #{ a: 1. b: 1. c: 1 } ].
> [ ] } collect: [ :each | [ n timesRepeat: each ] timeToRun ] " #(3705
> 894 130 157) "
>
> Clearly there is some optimisation to be done with the old implementation.

As you say, it's only matter of optimization of hashed collection
literal creation (and lone -> probably as well).

> I like the new syntax more, and I think we should contemplate about the
> relation
> between HashedCollection and JSObjectProxy a bit. What do you think?

One big (I mean BIG) con: this would be dialect-specific syntax. It
would be harder to write portable code with it. #{ -> } syntax is
_maybe_ considered as possibility in other smalltalk lists,
ocassionally, but definitely not #{ : } one.

> cheers, Balázs

Herby
Reply | Threaded
Open this post in threaded view
|

Re: autocomplete

shaun gilchrist
I ran into nearly the same problem my first week with amber and my immediate reaction was also "why not just use json style syntax?" but the more I get into the amber/smalltalk mindset the more I do not miss the ability to rapidly define/pass along anonymous objects. When I find myself reaching for anon objects ala JS it usually means:

a) the interface is not well defined for st and could be wrapped (for instance calling "ajax" function should really be a matter of creating an ajax object which you set the properties on via cascade and then a send message) 

AjaxWrapper new
  dataType: 'jsonp';
  data: #{
  'featureClass' -> 'P'.
  'style' -> 'full'.
  'maxRows' -> 12.
  'name_startsWith' -> 'foz'};
  success: [:d | console log: d];
    send.

b) I probably need to define a class instead of having this anonymous data structure floating around. 

However I do agree that the bug in which methods are passed along w/ the hash when serialized for js interop should be fixed. I ended up rolling a different method  HashedCollection>>asJS which yields a "pure" js obj. (in the example above I would make send utilize this asJS message)

asJS
| obj |
obj := <{}>.
self keysAndValuesDo: [:key :value |
value := value asJSON.
key := key asJSON.
<obj[key] = value>].
^obj

-Shaun

On Tue, May 29, 2012 at 9:09 AM, Herby Vojčík <[hidden email]> wrote:


Balázs Kósi wrote:
Hi!

On Tuesday, May 29, 2012 12:09:57 PM UTC+2, Herby wrote:

   Why new things? What is bad with HashedCollection? It had problems
   not a
   long time ago, but nowadays it should only have those properties
   (enumaerable) that are its keys.

You're right. I tried the example with the latest amber from the repo,
and it works,
and indeed HashedCollection has only its keys as enumerable properties, and
other smalltalk objects only their inst vars. I guess this is the
relevant code:
https://github.com/NicolasPetton/amber/blob/master/js/boot.js#L145

That means that the main reason for my change is gone. There are two other
aspects to consider:

1) Syntax:

#{ a: 1 }
#{ 'a' -> 1 }

I think pros for the new syntax is, that it's "lighter" and resembles
the js object literal syntax.

Resembling js syntax is not a pro (imo)! Amber is Smalltalk.


Pros for the old syntax is that it's a bit more flexible. You can write:
k := 'foo'. #{ k -> 1 }
or even
a := 'foo' -> 1. #{ a }

2) Performance:

n := 100000.
{
[ #{ 'a' -> 1. 'b' -> 1. 'c' -> 1 } ].
[ HashedCollection new at: 'a' put: 1; at: 'b' put: 1; at: 'c' put: 1;
yourself ].
[ #{ a: 1. b: 1. c: 1 } ].
[ ] } collect: [ :each | [ n timesRepeat: each ] timeToRun ] " #(3705
894 130 157) "

Clearly there is some optimisation to be done with the old implementation.

As you say, it's only matter of optimization of hashed collection literal creation (and lone -> probably as well).


I like the new syntax more, and I think we should contemplate about the
relation
between HashedCollection and JSObjectProxy a bit. What do you think?

One big (I mean BIG) con: this would be dialect-specific syntax. It would be harder to write portable code with it. #{ -> } syntax is _maybe_ considered as possibility in other smalltalk lists, ocassionally, but definitely not #{ : } one.

cheers, Balázs

Herby

Reply | Threaded
Open this post in threaded view
|

Re: autocomplete

Nicolas Petton
In reply to this post by Herby Vojčík
Herby Vojčík <[hidden email]> writes:

> Balázs Kósi wrote:
>> Hi!
>>
>> On Tuesday, May 29, 2012 12:09:57 PM UTC+2, Herby wrote:
>>
>>     Why new things? What is bad with HashedCollection? It had problems
>>     not a
>>     long time ago, but nowadays it should only have those properties
>>     (enumaerable) that are its keys.
>>
>> You're right. I tried the example with the latest amber from the repo,
>> and it works,
>> and indeed HashedCollection has only its keys as enumerable properties, and
>> other smalltalk objects only their inst vars. I guess this is the
>> relevant code:
>> https://github.com/NicolasPetton/amber/blob/master/js/boot.js#L145
>>
>> That means that the main reason for my change is gone. There are two other
>> aspects to consider:
>>
>> 1) Syntax:
>>
>> #{ a: 1 }
>> #{ 'a' -> 1 }
>>
>> I think pros for the new syntax is, that it's "lighter" and resembles
>> the js object literal syntax.
>
> Resembling js syntax is not a pro (imo)! Amber is Smalltalk.
>
>> Pros for the old syntax is that it's a bit more flexible. You can write:
>> k := 'foo'. #{ k -> 1 }
>> or even
>> a := 'foo' -> 1. #{ a }
>>
>> 2) Performance:
>>
>> n := 100000.
>> {
>> [ #{ 'a' -> 1. 'b' -> 1. 'c' -> 1 } ].
>> [ HashedCollection new at: 'a' put: 1; at: 'b' put: 1; at: 'c' put: 1;
>> yourself ].
>> [ #{ a: 1. b: 1. c: 1 } ].
>> [ ] } collect: [ :each | [ n timesRepeat: each ] timeToRun ] " #(3705
>> 894 130 157) "
>>
>> Clearly there is some optimisation to be done with the old implementation.
>
> As you say, it's only matter of optimization of hashed collection
> literal creation (and lone -> probably as well).
>
>> I like the new syntax more, and I think we should contemplate about the
>> relation
>> between HashedCollection and JSObjectProxy a bit. What do you think?
>
> One big (I mean BIG) con: this would be dialect-specific syntax. It
> would be harder to write portable code with it. #{ -> } syntax is
> _maybe_ considered as possibility in other smalltalk lists,
> ocassionally, but definitely not #{ : } one.
>

I fully agree. I really like the current syntax.

Nico


>> cheers, Balázs
>
> Herby

--
Nicolas Petton
http://nicolas-petton.fr
Reply | Threaded
Open this post in threaded view
|

Re: autocomplete

Balázs Kósi
In reply to this post by Herby Vojčík
 Hi!

One big (I mean BIG) con: this would be dialect-specific syntax. It
would be harder to write portable code with it. #{ -> } syntax is
_maybe_ considered as possibility in other smalltalk lists,
ocassionally, but definitely not #{ : } one.
I think it's not probable that other smalltalks will consider this syntax change.

Because as Bert writes [1]:

I see no reason for trying to partly mimic JSON in Squeak.

For one, you can always use


{#foo -> 1. #bar -> 42} as: Dictionary.


and because as shaunxcode writes:
but the more I get into the amber/smalltalk mindset the more I do not miss the ability to rapidly define/pass along anonymous objects.

You don't use dictionaries this way in smalltalk (*), so I
don't think the dynamic dictionary syntax will catch on
in other dialects.

On the other hand I don't agree with shaunxcode, we shouldn't write wrapper code
for all the js libraries out there, the more seamless the integration is, the faster
you can start using them. (**).

All in all, I don't think that the syntax for defining js objects will have any effect
on portability, but it's essential for good interfacing with the js world. IMHO
{ 'a' -> 1 } is a few more keystrokes, and clutter on the screen compared to
{ a: 1 }, but probably I will go with the official version.

cheers, Balázs

[1] http://lists.squeakfoundation.org/pipermail/squeak-dev/2012-May/164039.html

(*) When I do, I'm generating javascript code/interfacing javascript libs.
I usually write code that goes something like this:

jQuery ajax: [ :ajax |
    ajax
        url: 'http://ws.geonames.org/searchJSON';
        dataType: 'jsonp';
        data: [ :data |
            data
                featureClass: 'P';
                style: 'full';
                maxRows: 12;
                at: 'name_startsWith' put: 'foz' ];
        success: [ :d | console log: d ] asJsFunction ]

where the ajax block arg is a JSObject containing an OrderedCollection
of key-value pairs, with an appropriately implemented dnu, which
fills the collection, and creates new JSObjects upon receiving blocks.
The benefit of this pattern that you can do calculations, and fill the objects
conditionally in the blocks.

(**) I try to use amber with dojo, and have code like this:

Application >> initializeLayout

    self
        require: #('dijit/layout/BorderContainer')
        do: [ :dBorderContainer |
            layout := dBorderContainer newValue: #{
                id: 'appLayout'.
                design: 'sidebar'.
                gutters: true.
                liveSplitters: true }.
            self
                initializeCenterPane;
                initializeSidebar.
            document body appendChild: layout domNode.
            layout startup ]