invisible-college / statebus

All aboard the STATEBUS!!!
117 stars 5 forks source link

calls to bus.del from the client never reaches the server #24

Closed tkriplean closed 7 years ago

tkriplean commented 7 years ago

I believe this is because the to_delete handler in client.js never calls the server (https://github.com/invisible-college/statebus/blob/v5/client.js#L111)

Here is a test case. Run the server code below then access localhost:3333

bus = require('statebus/server')({
  port: 3333
  full_node: true
  client: (client) ->
    client.route_defaults_to(bus)
})

bus('test').to_delete = (key) ->
  # this handler is never called when client calls del!
  console.log 'DELETING', key

bus.http.get '/*', (r,res) => 

  html = """
      <script type="coffeedom">
      bus.honk = false

      dom.BODY = -> 
        t = fetch('/test')

        DIV null,
          "text: \#{t.text}"

          BUTTON 
            onClick: ->  
              if t.text
                console.log('trying to delete test from client')
                del t
            'Delete'

      #</script><script src="https://stateb.us/client5.js" server="istate://localhost:3333"></script>

      """

  res.send(html)

bus.save 
  key: 'test'
  text: "I'm here!"
toomim commented 7 years ago

This works now.