-
Notifications
You must be signed in to change notification settings - Fork 65
Updates for 0.12 #149
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
Updates for 0.12 #149
Conversation
Are we interested in adding the new lifecycle methods? |
Thanks for putting together this PR. I think adding the new lifecycle
methods would be great. Apologies on the delay on a release. I will create
a release after this PR.
…On Sat, Jun 2, 2018 at 16:23 Nathan Faubion ***@***.***> wrote:
Are we interested in adding the new lifecycle methods?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#149 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAVYy2qXZdoNDT0QI9Bx1dlrbTa19sf-ks5t4vQqgaJpZM4UV7UO>
.
|
One thing that's weird is the interplay between foreign import data ReactUnusedSnapshot :: Type
-- | Required fields for constructing a ReactClass.
type ReactSpecRequired state r =
( state :: state
, render :: Render
| r
)
type ReactSpecUnsafe props state r =
( unsafeComponentWillMount :: ComponentWillMount
, unsafeComponentWillReceiveProps :: ComponentWillReceiveProps props
, unsafeComponentWillUpdate :: ComponentWillUpdate props state
| r
)
-- | Optional fields for constructing a ReactClass.
type ReactSpecOptional props state snapshot r =
( componentDidMount :: ComponentDidMount
, componentDidCatch :: ComponentDidCatch
, componentWillUnmount :: ComponentWillUnmount
| ReactSpecSnapshot props state snapshot r
)
type ReactSpecSnapshot props state snapshot r =
( componentDidUpdate :: ComponentDidUpdate props state snapshot
, getSnapshotBeforeUpdate :: GetSnapshotBeforeUpdate props state snapshot
| r
)
type ReactSpecShouldComponentUpdate props state =
( shouldComponentUpdate :: ShouldComponentUpdate props state
)
type ReactSpecAll props state snapshot
= ReactSpecRequired state
+ ReactSpecOptional props state snapshot
+ ReactSpecShouldComponentUpdate props state
component
:: forall props state snapshot r spec
. Row.Union
(ReactSpecRequired (Record state) r)
(ReactSpecAll (Record props) (Record state) ReactUnusedSnapshot)
spec
=> Row.Nub spec (ReactSpecAll (Record props) (Record state) snapshot)
=> String
-> ReactClassConstructor (Record props) (Record state) r
-> ReactClass (Record props) This type signature is kind of bonkers, but the inference is actually decent. testChildren :: ReactClass { label :: String, children :: Children }
testChildren = component "TestChildren" \this -> do
let
getSnapshotBeforeUpdate _ _ = do
pure { foo: 42 }
render = do
props <- getProps this
pure $ div'
[ text props.label
, div' (childrenToArray props.children)
]
pure
{ state: { a: "start", b: 0 }
, render
, getSnapshotBeforeUpdate
}
And adding a corresponding testChildren :: ReactClass { label :: String, children :: Children }
testChildren = component "TestChildren" \this -> do
let
componentDidUpdate :: _
componentDidUpdate _ _ _ = do
pure unit
getSnapshotBeforeUpdate _ _ = do
pure { foo: 42 }
render = do
props <- getProps this
pure $ div'
[ text props.label
, div' (childrenToArray props.children)
]
pure
{ state: { a: "start", b: 0 }
, render
, getSnapshotBeforeUpdate
, componentDidUpdate
}
With the inverse (componentDidUpdate without getSnapshotBeforeUpdate) inferring I'm open to suggestions here. |
All of the updates look great. Thanks for adding context. Resolves #64 . I like your proposal for getSnapshotBeforeUpdate and componentDidUpdate, but I will have to put a bit more thought into this. |
I've gone ahead and pushed that approach. I've just consolidated it into a separate class so the signature doesn't look too bad. |
Also, I should point out I haven't tested this thoroughly beyond type checking/inference 😆 |
Thanks! And I will give it a whirl this weekend or Monday.
…On Sat, Jun 2, 2018 at 22:57 Nathan Faubion ***@***.***> wrote:
Also, I should point out I haven't tested this thoroughly beyond type
checking/inference 😆
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#149 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAVYy9DFCvuhnVr_PIMUs2BnXLqs3Q0yks5t41CVgaJpZM4UV7UO>
.
|
Something seems off, since I can set R.pureComponent "bad" \this ->
pure { state: { }
, render: 42
, shouldComponentUpdate: \_ _ -> pure true
} |
@paf31 Thanks! I had introduced a bug when I refactored it to use |
I've added |
Thanks! Is this PR about ready to go? If so, I will give the changes a test and merge. |
I don't think I have anything else to add to this PR. |
Looks great and works well! Thanks for all of your work on this. |
Also includes some renames for consistency.