Fork me on GitHub
#fulcro
<
2019-10-12
>
cjmurphy00:10:24

How do you catch a global keypress event? (:onKeyDown). I can catch on an input or a button that has the focus. I tried on the (nearly) outermost div but no response. I'm asking because setting up css refresh (which will be via a mutation that changes the :react-key on inj/style-element).

tony.kay01:10:11

React issue…I would think outermost div would do it.

wilkerlucio18:10:21

I do write components that specific for it, and those components use componentDidMount and componentWillUnmount to attach and dettach events, then you use something like: (key-handler {::key "s" ::action (fn ...)}

cjmurphy01:10:35

I know that there's an event whenever you alter the source code that I can use, the ^:dev/after-load refresh function. But now that I've asked, I'm curious about global keymappings...

tony.kay01:10:11

React Native helper library update: I added trial support for component co-located styles, which is implemented purely in the factory. See the bottom of the README for the idea. Interested in feedback/improvements, but I am finding it useful so far: https://github.com/fulcrologic/fulcro-native#react-factory With a bit more work we can make a macro version that would let us do the DOM-like thing: make the props optional, and let the keyword stand outside…be a nice parallel:

;; We're not quite here yet, but this would be nice:
(native/ui-button :.local-style "Hello world")

tony.kay01:10:57

So far I’ve not been impressed by native’s built-in StyleSheet.create, but it probably does some optimizations someone will want…either that or I’ll be really disappointed

tony.kay01:10:28

well, disappointment it is. All StyleSheet.create does is some validation and makes it immutable. https://github.com/facebook/react-native/blob/91f139b94118fe8db29728ea8ad855fc4a13f743/Libraries/StyleSheet/StyleSheet.js#L349 So, I think I already like mine better. 😜

magra16:10:10

I am porting an app from fulcro 2 to 3. So from legacy router to the new dynamic router. I want to trigger a load on changing a route. But I want to route immediately, not defer, because in most cases there will already be data in the db, the load is there in case something changed on the server. If I call load in will-enter, before calling route-immediate it gets called thrice (and the manual warned against this). What is an idiomatic way to route immediately and issue a load? Do I trigger it in Component will mount? (The manual warns against that too ;-))

tony.kay16:10:50

@magra So, staying on the legacy router is fine if you’ve already written to it. It will work better with SSR if you do and SSR.

tony.kay16:10:49

but, with regard to your actual question: If you need to do a load in will-enter, you use route-deferred. It is ok to use :componentDidMount, but just beware that there are reasons for a component to re-mount that may not coincide with your data’s lifecycle.

tony.kay16:10:01

will-enter probably makes more sense, and calling a mutation from there that checks app state, optionally issues the load, and also triggers the route change is what I’d recommend.

magra16:10:40

Is there a way to get route-deferred to signal target-ready before :post-mutation?

tony.kay16:10:50

:will-enter (fn [app _] (dr/route-deferred the-target (fn [] (comp/transact! this [(ensure-loaded)])))

tony.kay16:10:22

you could also put the target ready into that tx, if you want, or in the body of the mutation itself

magra16:10:12

ok! Thank you!!!!

magra16:10:14

Ah. Would it work to call target-ready and then route-deferred with route-deferred never calling target-ready?

tony.kay16:10:20

will-enter has to return one or the other…they do not side effect

tony.kay16:10:42

oh, I see you question…no, that would not work

tony.kay16:10:51

target-ready looks for a previously registered ident

tony.kay16:10:03

which the return of deferred registers

magra16:10:57

I see. Thank you!!!