import m from 'mithril';

function controller() {
  return {
    message: m.prop(''),

    send() {
      const { message } = this;

      if(message()) {
        // TODO: replace with emitter
        console.log(message());
        message('');
      }
    },
  };
}

function view(ctrl) {
  return (
    <div className="entry">
      <input
        className="entry__input"
        autocomplete="off"
        onchange={m.withAttr('value', ctrl.message)}
        value={ctrl.message()}
      />
      <button type="button" className="entry__send" onclick={() => ctrl.send()}>
        Send
      </button>
    </div>
  );
}

const Entry = { controller, view };

export default Entry;

@@ -89,20 +89,21 @@
    send(
+e
 ) %7B%0A
-
       co
@@ -127,16 +127,43 @@
  this;%0A%0A
+      e.preventDefault();%0A%0A
       if
@@ -328,19 +328,20 @@
  (%0A    %3C
-div
+form
  classNa
@@ -350,16 +350,48 @@
 =%22entry%22
+ onsubmit=%7Bctrl.send.bind(ctrl)%7D
 %3E%0A      
@@ -567,22 +567,8 @@
 tton
- type=%22button%22
  cla
@@ -591,57 +591,13 @@
 end%22
- onclick=%7B() =%3E ctrl.send()%7D%3E%0A        Send%0A      
+%3ESend
 %3C/bu
@@ -612,11 +612,12 @@
   %3C/
-div
+form
 %3E%0A  

implement enter to send