From e1486133eb04dba81ec65869507e37d7a66d49cb Mon Sep 17 00:00:00 2001 From: eric thul Date: Sun, 19 Nov 2017 10:35:18 -0500 Subject: [PATCH 1/3] Read/write refs on this Fixes #123 --- src/React.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/React.js b/src/React.js index c6e8308..33ad60c 100644 --- a/src/React.js +++ b/src/React.js @@ -13,7 +13,7 @@ exports.getProps = getProps; function getRefs(this_) { return function(){ - return this_.refs; + return this_; }; } exports.getRefs = getRefs; @@ -43,8 +43,7 @@ exports.getChildren = getChildren; function readRefImpl (this_) { return function(name) { return function() { - var refs = this_.refs || {}; - return refs[name]; + return this_[name]; } } } @@ -54,9 +53,7 @@ function writeRef(this_) { return function(name) { return function(node) { return function() { - var refs = this_.refs || {}; - refs[name] = node; - this_.refs = refs; + this_[name] = node; return {}; } } From 87f5b6a371e7b9e1acd95dae23d301df7008b602 Mon Sep 17 00:00:00 2001 From: eric thul Date: Sun, 19 Nov 2017 21:20:17 -0500 Subject: [PATCH 2/3] Reverting change to getRefs. Using the `ref` prop writes the ref to the `this.refs` object. However, setting a ref with a callback is not allowed to write to the frozen `this.refs`. It writes directly to `this` instead. --- src/React.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/React.js b/src/React.js index 33ad60c..84da9c5 100644 --- a/src/React.js +++ b/src/React.js @@ -13,7 +13,7 @@ exports.getProps = getProps; function getRefs(this_) { return function(){ - return this_; + return this_.refs; }; } exports.getRefs = getRefs; From 1f2899ab0bbda1148a3dd3b5bfbba14cd4728fde Mon Sep 17 00:00:00 2001 From: eric thul Date: Tue, 21 Nov 2017 08:22:24 -0500 Subject: [PATCH 3/3] Add documentation to ref props --- src/React/DOM/Props.purs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/React/DOM/Props.purs b/src/React/DOM/Props.purs index d67e968..4af5349 100644 --- a/src/React/DOM/Props.purs +++ b/src/React/DOM/Props.purs @@ -301,13 +301,16 @@ radioGroup = unsafeMkProps "radioGroup" readOnly :: Boolean -> Props readOnly = unsafeMkProps "readOnly" +-- | You can use `ref` to store a reference on `this.refs`. +-- | To access the stored reference, `getRefs` can then be used. ref :: String -> Props ref = unsafeMkProps "ref" --- | You can use `writeRef` to store a reference on `Refs`. +-- | You can use `writeRef` to store a reference on `this`. -- | ```purescript -- | div [ withRef (writeRef this "inputElement") ] [...] -- | ``` +-- | To access the stored reference, `readRef` can then be used. withRef :: forall access eff . (Nullable Ref -> Eff (refs :: ReactRefs (write :: Write | access) | eff) Unit)