Giter VIP home page Giter VIP logo

Comments (8)

valdrinkoshi avatar valdrinkoshi commented on July 19, 2024

Hi @zoechi, it is not a typo since the element is a <button>, and we execute the document.querySelector('#toast0').open() on the event onclick

from paper-toast.

zoechi avatar zoechi commented on July 19, 2024

@valdrinkoshi I see. Sorry for the noise.
I'm using Polymer from Dart and here it's not very common to use dom-bind.
I ported all element demos to Dart recently and there I replaced all dom-bind with an app-element. I found it weird that all examples assume the elements will be used on the body tag, not within the template of another component and such JS is used instead of Polymer binding.
Just saying, not action required/expected ;-)

from paper-toast.

valdrinkoshi avatar valdrinkoshi commented on July 19, 2024

We do it mainly to be concise in our examples, without requiring too much Polymer notation or other elements' knowledge. In a real application that code would be more verbose, something like this:

<!-- app-element.html -->

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-toast/paper-toast.html">
<link rel="import" href="../paper-button/paper-button.html">

<dom-module id="app-element">
    <template>
       <paper-toast id="toast0" text="Welcome back!"></paper-toast>
       <paper-button on-click="openToast">Login</paper-button>
    </template>
</dom-module>

<script>
    Polymer({
      is: 'app-element',
      openToast: function() {
        this.$.toast0.open();
      }
    });
</script>

from paper-toast.

zoechi avatar zoechi commented on July 19, 2024

That's how I translated it :)
Just my opinion - this way the demo source is better from an educational POV.

from paper-toast.

valdrinkoshi avatar valdrinkoshi commented on July 19, 2024

you're right, also looking at other docs (e.g. iron-collapse https://github.com/PolymerElements/iron-collapse) we do use Polymer notation. Will re-open and update the docs!

from paper-toast.

ebidel avatar ebidel commented on July 19, 2024

For something as simple as this, I don't think it makes sense to create a full element. We also want folks to know how to use elements/DOM outside of Polymer features. A 2-line example is much easier to grok than a list of imports, element, and polymer features. My $0.02.

from paper-toast.

valdrinkoshi avatar valdrinkoshi commented on July 19, 2024

@ebidel, would something like

<paper-button on-click="openToast">Open toast</paper-button>
<paper-toast id="toast" text="Welcome back!"></paper-toast>
...
openToast: function() {
  this.$.toast.open();
}

be better than just

<button onclick="document.querySelector('#toast').open()">Open toast</button>
<paper-toast id="toast" text="Welcome back!"></paper-toast>

The drawback of the first though is that it won't work out-of-the-box if you copy-paste it, while the second would just work

from paper-toast.

ebidel avatar ebidel commented on July 19, 2024

The first seems fine. I don't think the docs example code needs to be copy-and pasteable. We have the fuller demo examples and doc site for that :)

from paper-toast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.