-
Notifications
You must be signed in to change notification settings - Fork 76
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
Querying a React component #107
Comments
You can only interact with a react component through its public properties,
I think. You can subscribe to its events, like onchange, and copy its state
to your Pux state, then update the component with the state it just gave
you. I let react components manage their own state and get a copy of the
values I need using events.
…On Sun, Feb 26, 2017, 17:07 Karl Sutt ***@***.***> wrote:
Hi,
I've been using Elm a lot, but due to the inability to tap into the vast
sea of JS/React libraries I have started to look into PureScript and Pux.
I managed to mount https://github.com/zenoamaro/react-quill inside my toy
Pux app, but I can't seem to work out how to query the state of the
component. I would like to be able to keep track of the contents of the
editor in my Pux model (in order to persist them in the DB etc). Is it
currently possible with Pux? I haven't used React either, so I might be
missing something obvious.
Many thanks!
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#107>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AAzdmVcjWpmiTJDQqfdZ1gqFBfQ3S7azks5rggWmgaJpZM4MMjw->
.
|
Thanks for a quick response!
I see, yes. I'm currently just setting the state in the onChange handler for the component, but I could do other things in there. Is there an idiomatic way for notifying Pux of the changes happening inside a component -- like sending a Msg/Action or something? It needs to happen on the JS side afaict, as that's where the handler is, correct?
Sent from my phone.
Tervitades/Regards,
Karl Sutt
…On 26 Feb 2017, 23:12 +0000, Alex Berg ***@***.***>, wrote:
You can only interact with a react component through its public properties,
I think. You can subscribe to its events, like onchange, and copy its state
to your Pux state, then update the component with the state it just gave
you. I let react components manage their own state and get a copy of the
values I need using events.
On Sun, Feb 26, 2017, 17:07 Karl Sutt ***@***.***> wrote:
> Hi,
>
> I've been using Elm a lot, but due to the inability to tap into the vast
> sea of JS/React libraries I have started to look into PureScript and Pux.
>
> I managed to mount https://github.com/zenoamaro/react-quill inside my toy
> Pux app, but I can't seem to work out how to query the state of the
> component. I would like to be able to keep track of the contents of the
> editor in my Pux model (in order to persist them in the DB etc). Is it
> currently possible with Pux? I haven't used React either, so I might be
> missing something obvious.
>
> Many thanks!
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <#107>, or mute the
> thread
> <https://github.com/notifications/unsubscribe-auth/AAzdmVcjWpmiTJDQqfdZ1gqFBfQ3S7azks5rggWmgaJpZM4MMjw->
> .
>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub (#107 (comment)), or mute the thread (https://github.com/notifications/unsubscribe-auth/AAPWCs21I2q1E5PlI2f8xovULuOs8g9Dks5rggbHgaJpZM4MMjw-).
|
Attach a JS event using one of the functions in the Pux library to send JS
events to the action channel on which Pux responds. It's all standard JS
events, AFAIK, unless the React component has nonstandard events.
What's the specific problem you are having? Any code samples?
…On Sun, Feb 26, 2017, 17:41 Karl Sutt ***@***.***> wrote:
Thanks for a quick response!
I see, yes. I'm currently just setting the state in the onChange handler
for the component, but I could do other things in there. Is there an
idiomatic way for notifying Pux of the changes happening inside a component
-- like sending a Msg/Action or something? It needs to happen on the JS
side afaict, as that's where the handler is, correct?
Sent from my phone.
Tervitades/Regards,
Karl Sutt
On 26 Feb 2017, 23:12 +0000, Alex Berg ***@***.***>, wrote:
> You can only interact with a react component through its public
properties,
> I think. You can subscribe to its events, like onchange, and copy its
state
> to your Pux state, then update the component with the state it just gave
> you. I let react components manage their own state and get a copy of the
> values I need using events.
>
> On Sun, Feb 26, 2017, 17:07 Karl Sutt ***@***.***> wrote:
>
> > Hi,
> >
> > I've been using Elm a lot, but due to the inability to tap into the
vast
> > sea of JS/React libraries I have started to look into PureScript and
Pux.
> >
> > I managed to mount https://github.com/zenoamaro/react-quill inside my
toy
> > Pux app, but I can't seem to work out how to query the state of the
> > component. I would like to be able to keep track of the contents of the
> > editor in my Pux model (in order to persist them in the DB etc). Is it
> > currently possible with Pux? I haven't used React either, so I might be
> > missing something obvious.
> >
> > Many thanks!
> >
> > —
> > You are receiving this because you are subscribed to this thread.
> > Reply to this email directly, view it on GitHub
> > <#107>, or mute
the
> > thread
> > <
https://github.com/notifications/unsubscribe-auth/AAzdmVcjWpmiTJDQqfdZ1gqFBfQ3S7azks5rggWmgaJpZM4MMjw-
>
> > .
> >
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub (
#107 (comment)),
or mute the thread (
https://github.com/notifications/unsubscribe-auth/AAPWCs21I2q1E5PlI2f8xovULuOs8g9Dks5rggbHgaJpZM4MMjw-
).
>
>
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#107 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAzdmeJgi89s5Hsx9yaUg2SsWDKlszgZks5rgg2fgaJpZM4MMjw->
.
|
The problem I'm having is I can't see how to notify Pux of changes happening inside the React component. I've put together a gist with some of my code here https://gist.github.com/karls/dc25b4ed6a8837b7382e97afdb462423. Essentially, I would like to update my Pux model's As a disclaimer, I'm fairly certain that it's down to my inexperience with PS/Pux and React. I'm sure there is an obvious way to do this, but I can't seem to work out how. In Elm-land, the recommended approach is to use Ports to communicate with Javascript -- e.g subscribe to changes in a value that comes from a Javascript source. Although the documentation doesn't say that, I saw in the source that there is an |
Just an update from my side. I managed to get this working, more-or-less. I've updated the gist as well with code that works. I ended up doing it with a custom It would be nice to document this somehow. E.g, what if I also wanted to do something with the other 3 arguments in the component's |
I have an open pull request for an "evt" event handler for which you can
have any type event handler. You can probably do a variation of that, like
instead of passing the first argument, pass all the argument as an array.
…On Tue, Feb 28, 2017, 04:40 Karl Sutt ***@***.***> wrote:
Just an update from my side.
I managed to get this working, more-or-less. I've updated the gist as well
with code that works.
I ended up doing it with a custom onChange handler. But as you pointed
out, the React component's onChange is not a standard onChange event --
its signature is onChange(content, delta, source, editor). Luckily,
content is what I was interested in, so I could just pass a 1-argument
event handler in my own code.
It would be nice to document this somehow. E.g, what if I also wanted to
do something with the other 3 arguments in the component's onChange
handler?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#107 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAzdmU61MhBhvLGtf-qMBJseU1X_xzmcks5rg_mrgaJpZM4MMjw->
.
|
Ah, yes, I saw your pull request now. I had a quick play around with the type of event handler as in your pull request. I couldn't make it work.. I tried having the handler itself as a function using I suspect I'm missing something obvious, because I'm not sure how I would pass all the arguments as an array. The |
Another realisation. If I understand this correctly, the I think that even with the changes in your pull request it won't help with defining event handlers that receive more than one argument, because you have re-used Ideally, components wouldn't deviate from the way standard JS events are handled, but is there something we can do to make it possible to handle such strange, non-standard "events" in Pux? |
@karls - I mean adding some functions like below: Events.purs
Events.js
And used like this, but with better types to describe the value handled by the Action. MyApp.purs
|
I tried this out and this actually works rather well. The only thing I needed to change was the type signature for That |
Nice to hear it works, even if it's not perfect. I agree it needs better
typing. Can you share your code? Hard to help otherwise.
…On Thu, Mar 2, 2017, 13:30 Karl Sutt ***@***.***> wrote:
I tried this out and this actually works rather well. The only thing I
needed to change was the type signature for evt', which was giving a type
error on the event type variable.
That unsafeCoerce makes me sad. When/if the underlying component changes
its API with a version upgrade it'll crash at runtime, right? Then again,
upgrading dependencies blindly is never good.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#107 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAzdmdPOk3mtOO5vqElYrr4AKDUrPOv-ks5rhxjVgaJpZM4MMjw->
.
|
Yes, sorry. I was in a hurry when I left that comment. I've created an example project demonstrating the mechanism you've outlined https://github.com/karls/pux-react-component-test. |
I would like to do the same but with the current version. |
+1 for current version. I've spent a few fruitless hours on this and would very much appreciate any hints. |
Concerning doing the same with Pux version 10 I managed to integrate From my limited understanding, the problem seems to have been that Pux expects your What worked for me was using The editor itself was integrated with something like: |
@limick: would you be able to post a working code example (like an updated https://github.com/karls/pux-react-component-test)? |
@borsboom: Sure, see https://github.com/limick/pux-react-component-test/tree/pux-v11. I'm not very familiar with the node ecosystem, so I couldn't get |
@limick Thank you!! |
Hi,
I've been using Elm a lot, but due to the inability to tap into the vast sea of JS/React libraries I have started to look into PureScript and Pux.
I managed to mount https://github.com/zenoamaro/react-quill inside my toy Pux app, but I can't seem to work out how to query the state of the component. I would like to be able to keep track of the contents of the editor in my Pux model (in order to persist them in the DB etc). Is it currently possible with Pux? I haven't used React either, so I might be missing something obvious.
Many thanks!
The text was updated successfully, but these errors were encountered: