@@ -126,11 +126,12 @@ customElementBindingsTest() {
126126          '</my-custom-element>' 
127127        '</template>' );
128128
129-     mdv.instanceCreated. listen ( (fragment) {
129+     callback (fragment) {
130130      for  (var  e in  fragment.queryAll ('my-custom-element' )) {
131131        new  MyCustomElement .attach (e);
132132      }
133-     });
133+     }
134+     mdv.instanceCreated.add (callback);
134135
135136    div.query ('template' ).model =  model;
136137    performMicrotaskCheckpoint ();
@@ -161,6 +162,8 @@ customElementBindingsTest() {
161162
162163    expect (element.xtag.myPoint, null , reason:  'model was unbound' );
163164    expect (element.xtag.scaryMonster.health, 100 , reason:  'model was unbound' );
165+ 
166+     mdv.instanceCreated.remove (callback);
164167  });
165168
166169}
@@ -177,64 +180,45 @@ class MyCustomElement implements Element {
177180  Point  myPoint;
178181  Monster  scaryMonster;
179182
180-   StreamSubscription  _sub1, _sub2;
181- 
182183  MyCustomElement () :  this .attach (new  Element .tag ('my-custom-element' ));
183184
184185  MyCustomElement .attach (this .real) {
185186    real.xtag =  this ;
186187  }
187188
188- 
189189  get  attributes =>  real.attributes;
190+   get  bindings =>  real.bindings;
190191
191-   void   bind (String  name, model, String  path) {
192+   NodeBinding   createBinding (String  name, model, String  path) {
192193    switch  (name) {
193194      case  'my-point' : 
194-         unbind ('my-point' );
195-         attributes.remove ('my-point' );
196- 
197-         _sub1 =  new  PathObserver (model, path).bindSync ((v) {
198-           myPoint =  v;
199-         });
200-         return ;
201195      case  'scary-monster' : 
202-         unbind ('scary-monster' );
203-         attributes.remove ('scary-monster' );
204- 
205-         _sub2 =  new  PathObserver (model, path).bindSync ((v) {
206-           scaryMonster =  v;
207-         });
208-         return ;
196+         return  new  _MyCustomBinding (this , name, model, path);
209197    }
210-     real.bind (name, model, path);
198+     return   real.createBinding (name, model, path);
211199  }
212200
213-   void  unbind (String  name) {
214-     switch  (name) {
215-       case  'my-point' : 
216-         if  (_sub1 !=  null ) {
217-           _sub1.cancel ();
218-           _sub1 =  null ;
219-         }
220-         return ;
221-       case  'scary-monster' : 
222-         if  (_sub2 !=  null ) {
223-           _sub2.cancel ();
224-           _sub2 =  null ;
225-         }
226-         return ;
227-     }
228-     real.unbind (name);
201+   bind (String  name, model, String  path) =>  real.bind (name, model, path);
202+   void  unbind (String  name) =>  real.unbind (name);
203+   void  unbindAll () =>  real.unbindAll ();
204+ }
205+ 
206+ class  _MyCustomBinding  extends  mdv.NodeBinding  {
207+   _MyCustomBinding (MyCustomElement  node, property, model, path)
208+       :  super (node, property, model, path) {
209+ 
210+     node.attributes.remove (property);
229211  }
230212
231-   void  unbindAll () {
232-     unbind ('my-point' );
233-     unbind ('scary-monster' );
234-     real.unbindAll ();
213+   MyCustomElement  get  node =>  super .node;
214+ 
215+   void  boundValueChanged (newValue) {
216+     if  (property ==  'my-point' ) node.myPoint =  newValue;
217+     if  (property ==  'scary-monster' ) node.scaryMonster =  newValue;
235218  }
236219}
237220
221+ 
238222/** 
239223 * Demonstrates a custom element can override attributes [] = and remove. 
240224 * and see changes that the data binding system is making to the attributes. 
@@ -253,7 +237,9 @@ class WithAttrsCustomElement implements Element {
253237    real.xtag =  this ;
254238  }
255239
256-   void  bind (String  name, model, String  path) =>  real.bind (name, model, path);
240+   createBinding (String  name, model, String  path) => 
241+       real.createBinding (name, model, path);
242+   bind (String  name, model, String  path) =>  real.bind (name, model, path);
257243  void  unbind (String  name) =>  real.unbind (name);
258244  void  unbindAll () =>  real.unbindAll ();
259245}
0 commit comments