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

onload is fired continuously in template strings with reducers when compiled or run with babel or es2020 #17

Open
artcommacode opened this issue Jan 17, 2017 · 0 comments

Comments

@artcommacode
Copy link

Here's my minimal reproduction where init is continuously logged to the console:

const choo = require('choo')
const html = require('choo/html')
const app = choo()

app.model({
  reducers: {
    init: () => console.log('init')
  }
})

const view = (state, prev, send) => {
  return html`<div onload=${() => send('init', [])}></div>`
}

app.router([
  ['/', view]
])

const tree = app.start()
document.body.appendChild(tree)

which compiles to:

'use strict';

var _templateObject = _taggedTemplateLiteral(['<div onload=', '></div>'], ['<div onload=', '></div>']);

function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }

var choo = require('choo');
var html = require('choo/html');
var app = choo();

app.model({
  reducers: {
    init: function init() {
      return console.log('init');
    }
  }
});

var view = function view(state, prev, send) {
  return html(_templateObject, function () {
    return send('init', []);
  });
};

app.router([['/', view]]);

var tree = app.start();
document.body.appendChild(tree);

I've opened the issue here at @yoshuawuyts request. A runnable example can be found at https://github.com/artcommacode/choo-onload-example, please let me know if you need any further information.

@artcommacode artcommacode changed the title onload is fired continuously in template strings with reducers when compiled or run with babel and es2020 onload is fired continuously in template strings with reducers when compiled or run with babel or es2020 Jan 17, 2017
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

1 participant