Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unbinding a model does not remove the template contents from the page #12687

Closed
sethladd opened this issue Aug 23, 2013 · 7 comments
Closed

Unbinding a model does not remove the template contents from the page #12687

sethladd opened this issue Aug 23, 2013 · 7 comments
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures
Milestone

Comments

@sethladd
Copy link
Contributor

This behavior changed recently, and polymer.dart hasn't caught up.

This works in polymer.js:

<html>
<head>
    <title>Test</title>
  <script src="polymer.min.js"></script>
</head>
<body>

    <p>
      The below will appear and disappear if the model is not null,
      and will disappear if the model is null. Or, it should.
    </p>

    <template id="tmpl" bind>
      <p>Hello {{msg}}</p>
    </template>
    
    <!-- or... -->
    
    <p>
      The below will appear and disappear if the conditional value
      is true or false.
    </p>
    
    <!-- because we are binding a boolean directly as the model,
         there's no further path for the {{ and }} -->

    <!-- also, the bind attribute here is optional -->
    <template id="tmpl2" if="{{}}">
      <p>Activated!</p>
    </template>
    
    <script>

    var tmpl = document.getElementById('tmpl');
    var tmpl2 = document.getElementById('tmpl2');

    var model = {'msg': 'world'};

    setInterval(function() {
      if (tmpl.model !== undefined) {
        console.log('unbinding');
        tmpl.model = undefined;
        tmpl2.model = false;
      } else {
        console.log('binding');
        tmpl.model = model;
        tmpl2.model = true;
      }
    }, 1000);

    </script>
  </body>
</html>

Every second, the contents of #tmpl are added, then removed.

This doesn't work in polymer.dart today. Here's the code to test:

import 'dart:html';
import 'dart:async';

class Message {
  String msg;
}

main() {
  Message message = new Message()..msg = 'world';
  TemplateElement template = query('#tmpl');
  TemplateElement ifTemplate = query('#tmpl2');
  
  new Timer.periodic(const Duration(seconds: 1), (_) {
    if (template.model != null) {
      template.model = null;
      ifTemplate.model = false;
    } else {
      template.model = message;
      ifTemplate.model = true;
    }
  });
  
}

<!DOCTYPE html>

<html>
  <head>
    <title>index</title>
    <script src="packages/polymer/boot.js"></script>
  </head>
 
  <body>

    <!-- BUG: https://code.google.com/p/dart/issues/detail?id=11983 -->
    <!-- Not sure why I need an if here. Why isn't bind/unbind enough? -->

    <p>
      The below will appear and disappear if the model is not null,
      and will disappear if the model is null. Or, it should.
    </p>

    <template id="tmpl" bind>
      <p>Hello {{msg}}</p>
    </template>
    
    <!-- or... -->
    
    <p>
      The below will appear and disappear if the conditional value
      is true or false.
    </p>
    
    <!-- because we are binding a boolean directly as the model,
         there's no further path for the {{ and }} -->

    <!-- also, the bind attribute here is optional -->
    <template id="tmpl2" if="{{}}">
      <p>Activated!</p>
    </template>
    
    <script type="application/dart" src="index.dart"></script>
  </body>
</html>

@sethladd
Copy link
Contributor Author

Issue #11983 has been merged into this issue.

@jmesserly
Copy link

Added Library-MDV label.

@sethladd
Copy link
Contributor Author

I believe this will get fixed in time for 1.0


Removed Priority-Medium label.
Added Priority-High label.

@larsbak
Copy link

larsbak commented Aug 27, 2013

Added this to the M7 milestone.

@sigmundch
Copy link
Member

Removed this from the M7 milestone.
Added this to the M8 milestone.

@sigmundch
Copy link
Member

I believe this is fixed now in version 0.8.1 (I see a blinking "Activated!" and "world").


Added Fixed label.

@sethladd
Copy link
Contributor Author

sethladd commented Oct 8, 2013

Super awesome, thanks!

@sethladd sethladd added Type-Defect P1 A high priority bug; for example, a single project is unusable or has many test failures labels Oct 8, 2013
@sethladd sethladd added this to the M8 milestone Oct 8, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures
Projects
None yet
Development

No branches or pull requests

4 participants