Fork me on GitHub
#rum
<
2017-04-21
>
kurt-o-sys08:04:08

I'm trying out rum with re-natal, just trying a few things. I want to add push notifications with OneSignal https://github.com/geektimecoil/react-native-onesignal I'm stuck at https://github.com/geektimecoil/react-native-onesignal#usage , translating this to rum/cljs:

OneSignal.addEventListener('received', this.onReceived);
        OneSignal.addEventListener('opened', this.onOpened);
        OneSignal.addEventListener('registered', this.onRegistered);
        OneSignal.addEventListener('ids', this.onIds);
This is how far I got:
(def OneSignal (js/require "react-native-onesignal"))
(def one-signal-mixin
  {
   :will-mount (fn [state]
                 (doto OneSignal
                   (.addEventListener 'received', this.onReceived)
                   (.addEventListener 'opened', this.onOpened)
                   (.addEventListener 'registered', this.onRegistered)
                   (.addEventListener 'ids', this.onIds))
                state)
   })
but, this.onxxx, what is the this?

Niki08:04:55

@jeroenvandijk is that some special component that breaks everything or any component does? Can you create an issue, I’ll see what can be done about it

Niki08:04:51

@kurt-o-sys there’s no “this” in rum component

kurt-o-sys08:04:19

Yeah, I know, but how do I 'translate' the this inside the mixin?

jeroenvandijk08:04:26

@tonsky I think it breaks for any component, but I’ll double check. I am doing some weird things with routing and stuartsierra’s Component lib (and some other things), so I’ll try to make a minimal example where this also happens

Niki08:04:58

@kurt-o-sys it’s not clear what this is in js code either

Niki08:04:16

usually this points to some specific object. Use the object directly instead

kurt-o-sys08:04:57

thx... I'll check it - it's probably the Component itself... I'll check.

Niki08:04:59

@jeroenvandijk even if you doesn’t have minimal case, just create an issue so I don’t forget

misha08:04:19

@kurt-o-sys I think you just need to define inline callbacks there with whatever signature is expected (`(fn [e] ...)` or (fn [ids] ...)), like

:will-mount (fn [state]
                 (doto OneSignal
                   (.addEventListener 'received', (fn [e] ...))
...
                state)

kurt-o-sys08:04:51

Yeah, right... it's just adding functions 😛

misha08:04:03

and since you are wrapping this up in a reusable mixin - you might receive those as mixin arguments, or fetch from state, or whatever you'll come up with

kurt-o-sys08:04:50

oh... right, for now, I just defined functions. Will see if it works fine.

misha08:04:27

in plain react people just do

component {
  onClick: ...
  render: (... thing.addEventListener(onclick, this.onClick))
}
wanna-be-OOP style