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

Setting default data to template[is="dom-bind"] #51

Open
8 tasks done
tpluscode opened this issue Feb 2, 2017 · 3 comments
Open
8 tasks done

Setting default data to template[is="dom-bind"] #51

tpluscode opened this issue Feb 2, 2017 · 3 comments

Comments

@tpluscode
Copy link

tpluscode commented Feb 2, 2017

Description

It is possible to use data binding in the demo-snippet template but there is no simple way for setting initially bound values.

Expected outcome

Setting up data binding without resorting to document.querySelector etc. to select the <template> instance. Also, it would be nice to then display the bound data in marked-element along the demoed element(s). Here's how I imagine the usage

<demo-snippet>
  <template id="defaultBinding" is="dom-bind">
    <paper-input value="{{data.someText}}"></paper-input>
    <paper-input value="{{data.someText}}"></paper-input>
  </template>

  <script>
    function defaultBinding() {
      return {
        someText: 'Lorem Ipsum Dolor'
      }
    }
  </script>
</demo-snippet>

For lack of a better idea, I assume that there has to be a global function named same as the snippet's template. If so, then the data returned from this function will be assigned to template.data property. Alternatively, I'm considering iterating the keys of the object and setting on the template so that it won't be necessary to prefix everything with data.

Also, I that in addition to a function, a variable could be set up in the script like window.defaultBinding = {}

I'm also not too keen on the idea of global function/variable. I'd like to hear any suggestions.

Browsers Affected

  • Chrome
  • Firefox
  • Safari 9
  • Safari 8
  • Safari 7
  • Edge
  • IE 11
  • IE 10
@notwaldorf
Copy link
Contributor

notwaldorf commented Feb 2, 2017

I think I'm a little confused...why can't you just set the property on the template? i.e. defaultBinding.data = {...}? This is how a dom-bind would be used regardless of a demo-snippet.

Secondly, if that doesn't work, you can just put the dom-bind outside of the demo-snippet, and set the data on it as above:

<template is="dom-bind" id="scope">
  <demo-snippet>
    <template>[[scope.someText]]</template>
  </demo-snippet>
</template>
<script>
  scope.someText = 'meow'
</script>

@tpluscode
Copy link
Author

Setting the value is easy. What I wanted more is actually showcasing the values. See the screenshot in my PR. I added an additional marked-element which renders the dom-bind's model.

@aemonge
Copy link

aemonge commented Aug 1, 2017

How would this work with polymer 2 ?

      <demo-snippet>
        <template id="scope">
          <dom-bind id="scope">
            <template id="scope">
              La [[scope.hola]] caracola

              <script>
                /* eslint-disable */
                scope = {
                  hola: 'hola jesus'
                };
              </script>
            </template>
            <script>
              /* eslint-disable */
              scope = {
                hola: 'hola mundo'
              };
            </script>
          </dom-bind>
          <script>
            /* eslint-disable */
            scope = {
              hola: 'hola niá'
            };
          </script>
        </template>
        <script>
          /* eslint-disable */
          scope = {
            hola: 'hola guero'
          };
        </script>
      </demo-snippet>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants