How to access detail from core-signal event in polymer.dart?

126 views Asked by At

I am working on a web app in polymer.dart. When I use core-signal, I am unable to access the detail. Here's some of the code that I'm using...

main_app.dart

class MainApp extends PolymerElement {

  onClick(Event event, var detail, Node sender) {
    print('button clicked');
    fire("core-signal",  detail:{'name':'button-click', 'data':0});
  }

  ready() { 
    super.ready();
  }
}

canvasContainer.html

<link rel="import" href="../../packages/polymer/polymer.html">
<link rel="import" href="../../packages/core_elements/core_signals.html">

<polymer-element name="canvas-container">
  <div>
    <template>
      <core-signals on-core-signal-button-click="{{testAction}}"></core-signals>
      <div>
        <canvas id="canvas"></canvas>
      </div>
    </template>
  </div>
  <script type="application/dart" src="canvasContainer.dart"></script>
</polymer-element>

canvasContainer.dart

class CanvasContainer extends PolymerElement {
 // more code up here, but irrelevent
 testAction(Event e, var detail, Node sender) {
    print('event has been received');
    print(detail);
    context.moveTo(0, 0);
    context.lineTo(1000, 1000);
    context.stroke();
  }
}

MainApp receives the button click, and sends the "core-signals" event. In the canvasContainer though, the event does get received, but when I print the detail, it just says "0". Any insight into the problem is appreciated.

1

There are 1 answers

0
Jake MacDonald On BEST ANSWER

The way core-signal works, the data key of your detail object is what actually gets set as the detail of the event. The name property is then used to build the event type (it will be core-signal-$name).

See the docs here https://github.com/Polymer/core-signals/blob/master/core-signals.html#L79