marko-js-archive / marko-widgets

[LEGACY] Module to support binding of behavior to rendered UI components rendered on the server or client
http://v3.markojs.com/docs/marko-widgets/
MIT License
142 stars 40 forks source link

Multiple `w-bind`s inside one template. #140

Closed oxala closed 8 years ago

oxala commented 8 years ago

Apparently marko3 (or marko-widgets6, not sure which module exactly) stopped understanding two (or more) w-binds inside one template.

Whenever such case happens, it only sees the last w-bind it found and applies it to all w-binded elements in the template.

Imagine the template.marko file with content:

<div w-bind="./index">
    <div w-bind="./widget"></div>
</div>

The result of that inside template.marko.js would be something like this:

function create(__helpers) {
  var __widgetType = {
          name: "/dummyComponent/widget",
          def: function() {
            return require("./widget");
          }
        },
      __markoWidgets = require("marko-widgets"),
      __widgetAttrs = __markoWidgets.attrs,
      str = __helpers.s,
      empty = __helpers.e,
      notEmpty = __helpers.ne,
      escapeXml = __helpers.x,
      __loadTag = __helpers.t,
      w_widget = __loadTag(require("marko-widgets/taglib/widget-tag")),
      attr = __helpers.a,
      attrs = __helpers.as;

  return function render(data, out) {
    w_widget({
        type: __widgetType,
        _cfg: data.widgetConfig,
        _state: data.widgetState,
        _props: data.widgetProps,
        _body: data.widgetBody,
        renderBody: function renderBody(out, widget) {
          out.w("<div" +
            attr("id", widget.id) +
            attrs(__widgetAttrs(widget)) +
            ">");

          w_widget({
              type: __widgetType,
              _cfg: data.widgetConfig,
              _state: data.widgetState,
              _props: data.widgetProps,
              _body: data.widgetBody,
              renderBody: function renderBody(out, widget) {
                out.w("<div" +
                  attr("id", widget.id) +
                  attrs(__widgetAttrs(widget)) +
                  "></div>");
              }
            }, out);

          out.w("</div>");
        }
      }, out);
  };
}

(module.exports = require("marko").c(__filename)).c(create);

It's not necessary to have w-bind nested. Having then one after another produce the same result of only the last one being recognised and added to all w-bind elements.

patrick-steele-idem commented 8 years ago

Hey @oxala, just wanted to let you know that I was able to reproduce the problem. I am still investigating a fix. I'll update when I know more. Thanks for reporting the problem!

patrick-steele-idem commented 8 years ago

This problem was due to a bug in Marko: https://github.com/marko-js/marko/issues/303

A new version of marko has been published with a fix. Test cases added to marko-widgets. This should work now, but please let me know if you see any issues. Thanks!

oxala commented 8 years ago

All good, thank you very much!