From 767a5e27cfc05c7f4a45a7ecf21bf6756d02de05 Mon Sep 17 00:00:00 2001 From: Daniel Ma Date: Tue, 19 Dec 2017 11:47:22 -0800 Subject: [PATCH 1/2] Always include node in event callbacks This is a big change, but I think it would make development a lot more pleasant. Similar to working with React in a browser context, there are a lot of reasons that having a reference to a `Node` is useful. One of the most basic React DOM cases is text inputs. You create the input, and use `event.target.value` to set the state of your component. In react-blessed, having access to nodes in events would be useful, but they're largely not available (except `focus` and `blur` events). Because of this, I end up needing to create refs for almost every element, which isn't _necessarily_ bad, but my preference would be to just have access to the node in event callbacks. --- examples/form.jsx | 2 +- examples/framer.js | 6 +++--- src/fiber/events.js | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/form.jsx b/examples/form.jsx index 265bb26..43f4142 100644 --- a/examples/form.jsx +++ b/examples/form.jsx @@ -11,7 +11,7 @@ class Form extends Component { name: '', }; - this.submit = data => this.setState(state => ({name: data})); + this.submit = (_form, data) => this.setState(state => ({name: data})); this.cancel = _ => console.log('Form canceled'); } render() { diff --git a/examples/framer.js b/examples/framer.js index 9482a1f..ceb0a42 100644 --- a/examples/framer.js +++ b/examples/framer.js @@ -47,7 +47,7 @@ class Demo extends React.Component { */ } - handleMouseDown = (pos, pressY, event) => { + handleMouseDown = (pos, pressY, node, event) => { if (this.state.isPressed === false) { const {y} = event; this.setState({ @@ -57,14 +57,14 @@ class Demo extends React.Component { originalPosOfLastPressed: pos, }); } else { - this.handleMouseMove({ + this.handleMouseMove(node, { ...event, action: 'fake-mousemove', }); } }; - handleMouseMove = (event) => { + handleMouseMove = (_node, event) => { if (event.action !== 'fake-mousemove') { return; } diff --git a/src/fiber/events.js b/src/fiber/events.js index cca641e..46b79c4 100644 --- a/src/fiber/events.js +++ b/src/fiber/events.js @@ -25,9 +25,8 @@ const eventListener = (node, event, ...args) => { */ if (typeof handler === 'function') { - if (event === 'focus' || event === 'blur') { - args[0] = node; - } + args[0] = node; + handler(...args); } }; From f3d892b86da7e933f148751844177ee1bdc0c4d6 Mon Sep 17 00:00:00 2001 From: Daniel Ma Date: Wed, 20 Dec 2017 08:55:04 -0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20don't=20blow=20away=20the=20first=20?= =?UTF-8?q?argument=20=F0=9F=98=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fiber/events.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/fiber/events.js b/src/fiber/events.js index 46b79c4..2514d24 100644 --- a/src/fiber/events.js +++ b/src/fiber/events.js @@ -25,9 +25,7 @@ const eventListener = (node, event, ...args) => { */ if (typeof handler === 'function') { - args[0] = node; - - handler(...args); + handler(node, ...args); } };