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
141 stars 40 forks source link

Disallow multiple w-bind in a single template #95

Open maberer opened 8 years ago

maberer commented 8 years ago

We should break compiling a template if it contains more than 1 w-bind attribute. There is probably no good reason (bad practice) to to that (and often a mistake if not aware)... additionally, it could cause strange effects like missing events in a parent widget.

I ran into the problem when having the following bad template (extremely simplified):

<div w-bind>
    <form w-bind w-onsubmit="handleSubmit">
        <div>
            <button>Submit</button>
        </div>
   </form>
</div>

Be aware of the 2 w-bind attributes!

further having (in the widget implementation code):

handleSubmit: function(event, el) {
    this.emit('submit', {});
    event.preventDefault();
}

PROBLEM: The "submit" event of the form emitted by this widget would never reach the parent widget.

maberer commented 8 years ago

People might use the following statement with multiple w-bind. This would (at least) not cause strange effects (since the two sections are mutual exclusive...) - but I think it is bad practice nevertheless...

<if test="isLink">
    <a w-bind> ... </a>
</if>
<else>
    <button w-bind> ... </button>
</else>