[Opa] is there a way to "flush" Dom events?

Owen Gunden ogunden at phauna.org
Mon Jan 23 04:21:18 UTC 2012


Aha! I think I get @async. It means, "when you call this function it
will return immediately, while continuing to execute in the
background".. which would imply that I can't return anything from an
@async function, and indeed when I try:

Error
File "test2.opa", line 5, characters 8-10, (5:8-5:10 | 119-121)
@async lambdas must return void

That just leaves @publish_async. Is that just synonymous with
@publish @async?

Thanks for bearing with me.
 - O

On Sun, Jan 22, 2012 at 11:08 PM, Owen Gunden <ogunden at phauna.org> wrote:
> It works like magic. I want to grok the magic. What does @async do? I
> can't find it documented anywhere. It is necessary for the magic to
> work though.
>
> I have pondered about @server, @client, @both, @both_implem, @publish,
> @publish_async, and now @async. I want to understand better than I do.
> What I get so far:
>
> @server - put the code on the server
> @client - put the code on the client
> @both - put the code in both places, usually
> @both_implem - put the code in both places, always (? never had to use this yet)
> @publish - override server_private security check (e.g. to allow
> client to call a function that does db access)
> @publish_async - ?
> @async - ?
>
> On Sun, Jan 22, 2012 at 9:00 PM, Frederic Ye <frederic.ye at mlstate.com> wrote:
>> Depending on the browser, the dom transformation seems to be handled different ways (before, after ...)
>>
>> Here is a code you can try :
>>
>> import stdlib.themes.bootstrap
>>
>> @server @async
>> // just a busy loop to cause a delay for demonstration purposes
>> busyness(remaining:int) =
>>  do Scheduler.wait(2000)
>>  process_form()
>>
>> @client
>> process_form() =
>>  foo = Dom.get_value(#foo_input)
>>  do Dom.hide(#formdiv)
>>  do Dom.transform([#success <- "you said { foo }"])
>>  Dom.show(#success)
>>
>> @client
>> freeze_button_and_go(_) =
>>  do Dom.add_class(#submit, "disabled")
>>  do Dom.set_enabled(#submit, {false})
>>  do Dom.transform([#submit_going <- "going..."])
>>  do busyness(50)
>>  void
>>
>> show_form() =
>>  <div id=#formdiv onready={_ -> Dom.give_focus(#foo_input)}>
>>   <form method="get" onsubmit={freeze_button_and_go} action="javascript:void(0)">
>>   <fieldset>
>>    <div id=#foo_div class="clearfix">
>>     <label for="foo_input">foo:</label>
>>     <div class="input">
>>      <input class="xlarge"
>>             id=#foo_input
>>             type="text" name="foo_input" size="25"/>
>>     </div>
>>    </div>
>>    <div class="actions">
>>     <button class="btn primary" id=#submit>go</button>
>>     <span class="help-inline" id=#submit_going></span>
>>    </div>
>>   </fieldset>
>>   </form>
>>  </div>
>>  <div id=#success/>
>>
>> server =
>>  Server.one_page_server("test", show_form)
>>
>> I'll let you study it. If you have any questions, do not hesitate to ask ;)
>>
>> On 23 janv. 2012, at 02:17, Owen Gunden wrote:
>>
>>> Hello! I've attached some test code that presents a tiny form with a
>>> toy response.
>>>
>>> I would like the "go" button to grey out right away after it's
>>> clicked. However, my client doesn't render the Dom changes until after
>>> the entire onSubmit handler returns (including the call to busyness()
>>> which takes a while).
>>>
>>> Is there some buffering up of Dom events that are to be sent to the
>>> client, and if so, is there a way to flush them? If not, any
>>> suggestions on another way to get immediate feedback to the user when
>>> they've clicked the button?
>>>
>>> Thanks!
>>> <test.opa>_______________________________________________
>>> Opa mailing list
>>> Opa at lists.owasp.org
>>> https://lists.owasp.org/mailman/listinfo/opa
>>


More information about the Opa mailing list