diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-01 11:40:24 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-01 11:52:31 +0900 |
commit | adcaf2aa48d0453f231268f5db168376c08e4e6b (patch) | |
tree | d20e4770644e504c2997cc80c17c5cae355f108e /src/console | |
parent | 95c095f366106952d25982f12d99e4858c54cdb9 (diff) |
message passing by helper functions
Diffstat (limited to 'src/console')
-rw-r--r-- | src/console/console.js | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/console/console.js b/src/console/console.js index f8a91a6..67b9eab 100644 --- a/src/console/console.js +++ b/src/console/console.js @@ -1,41 +1,42 @@ import './console.scss'; +import * as messages from '../shared/messages'; const parent = window.parent; // TODO consider object-oriented var prevValue = ""; -const blurData = () => { - return JSON.stringify({ +const blurMessage = () => { + return { type: 'vimvixen.commandline.blur' - }); + }; }; -const keydownData = (input) => { - return JSON.stringify({ +const keydownMessage = (input) => { + return { type: 'vimvixen.commandline.enter', value: input.value - }); + }; }; -const keyupData = (input) => { - return JSON.stringify({ +const keyupMessage = (input) => { + return { type: 'vimvixen.commandline.change', value: input.value - }); + }; }; const handleBlur = () => { - parent.postMessage(blurData(), '*'); + messages.send(parent, blurMessage()); }; const handleKeydown = (e) => { switch(e.keyCode) { case KeyboardEvent.DOM_VK_ESCAPE: - parent.postMessage(blurData(), '*'); + messages.send(parent, blurMessage()); break; case KeyboardEvent.DOM_VK_RETURN: - parent.postMessage(keydownData(e.target), '*'); + messages.send(parent, keydownMessage(e.target)); break; } }; @@ -44,7 +45,7 @@ const handleKeyup = (e) => { if (e.target.value === prevValue) { return; } - parent.postMessage(keyupData(e.target), '*'); + messages.send(parent, keyupMessage(e.target)); prevValue = e.target.value; }; |