Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mountain/1409763 to your computer and use it in GitHub Desktop.
Save mountain/1409763 to your computer and use it in GitHub Desktop.
How to bind events in bean? With qwery and bonzo but without ender
###
csmain.coffee
link for this section:
http://playground.wahlque.org/tutorials/coffeescript/004-webworkers/
###
define [
'underscore',
'domReady',
'qwery',
'bonzo',
'bean',
'cs!/wahlque/util/url'
], (_, domReady, qwery, bonzo, bean, url) ->
$ = (selector) -> bonzo(qwery(selector))
q = (selector) -> document.querySelectorAll(selector)
domReady( ->
ps = url.params()
ps['a'] = 5 if not ps['a']
ps['b'] = 10 if not ps['b']
ctx =
keys: _.keys(ps)
vals: ps
list = _.template(
"<ul>
<form action='/tutorials/coffeescript/004-webworkers/' method='get'>
<% _.each(keys, function(key) { %>
<li><%= key %>: <input type='text' name='<%= key %>' value='<%= vals[key] %>'></li>
<% }); %>
<input type='submit' value='Submit' />
</form>
</ul>",
ctx
)
$('#params').html(list)
worker = new Worker 'worker.js'
worker.onmessage = (e) ->
data = 'result: ' + e.data
$('#result').append("<li>#{data}</li>")
true
invoke = ->
console.info('start of calling from page')
worker.postMessage( _.values(ps))
console.info('end of calling from page')
true
bean.add(
$('#btn'), 'click', (-> invoke()), q
)
true
)
@mountain
Copy link
Author

The method used at the line 52 dose not work. Anyone can help?

@mountain
Copy link
Author

Finally I solve it by myself. Just using get() method to fetch out the dom elements.

See https://github.com/Wahlque/tutorials/blob/master/coffeescript/004-webworkers/csmain.coffee#52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment