Skip to content

Read/write refs on this #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
}
Expand All @@ -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 {};
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/React/DOM/Props.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down