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

render outside of target #5

Open
benzen opened this issue Jan 6, 2018 · 3 comments
Open

render outside of target #5

benzen opened this issue Jan 6, 2018 · 3 comments
Labels

Comments

@benzen
Copy link
Contributor

benzen commented Jan 6, 2018

Here is an exemple

<html>
  <head>
    <script src="/js/magery-compiler.js"></script>
    <script src="/js/magery-patcher.js"></script>
    <script src="/js/redux.js"></script>
    <template data-tagname="app-title">
      <h1>{{text}}</h1>
    </template>
  </head>
  <body>
    <app></app>

    <script>
      var components = MageryCompiler.compile('template');

      // create a store
      var store = Redux.createStore(function (state, action) {
          if (typeof state === 'undefined') {
            return {
              title: "fuck mennn",
              count: 0
            };
           }
           switch (action.type) {
            case 'INCREMENT':
              return {count: state.count + 1};
            case 'DECREMENT':
              return {count: state.count - 1};
            default:
              return state;
           }
       });

       var target = document.querySelector('app');
       var handlers = {};

       function render() {
          console.log(store.getState())
          components['app-title'](target, store.getState(), handlers);
       }

       // add event handlers using Magery
       handlers.increment = function () {
           store.dispatch({type: 'INCREMENT'});
       };
       handlers.decrement = function () {
           store.dispatch({type: 'DECREMENT'});
       };

       // update the page when the store changes
       store.subscribe(render);

       // initial render
       render();
    </script>
  </body>
</html>

I've noticed that in the produced dom, the tree rendered by outside ouf the target

<html><head>
...
    <template data-tagname="app-title">
      <h1>{{text}}</h1>
    </template>
  </head>
  <body>
    <app-title>
      <h1></h1>
    </app-title><app></app>
    <script>
...

</body></html>
@benzen
Copy link
Contributor Author

benzen commented Jan 6, 2018

What i see as a side effect of this, a second render will produce a new tree

@caolan
Copy link
Owner

caolan commented Jan 8, 2018

This appears to happen when the tag names are mismatched. So when the target does not match the template tag being rendered onto it. I'm not sure what the appropriate action is in this case, but it should not render a new adjacent tree... perhaps it should just produce an error.

@benzen
Copy link
Contributor Author

benzen commented Jan 9, 2018 via email

@caolan caolan added the bug label Jan 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants