Fork me on GitHub
#rum
<
2016-11-01
>
jupl02:11:04

@martinklepsch Ah so is the magic the use of ^:dynamic? I’m still new to Clojure so I just came across that.

martinklepsch09:11:29

@jupl basically, yes. Since component context is a React thing and we don't run React on the server we want a similar construct. Clojure's dynamic vars provide that kind of feature. I think usually it is advised to use it as little as possible but in this case I believe it is the right choice.

jupl12:11:02

@martinklepsch Yeah I totally agree. Thanks!

miguelb16:11:04

Hi everyone, is there a way to to export a rum export for use in a large react application? For example: (def ^:export rumComp (rum/defc hello-world [] [:h1 (:text "hello world”)])) could I then use <rumComp /> in plain React?

miguelb16:11:30

Trying to find ways to use clojurescript at work

Niki17:11:01

Well, you'll need a react class then

Niki17:11:00

Actually, you might use rumComp directly as a factory function

Niki17:11:38

It probably doesn't keep export attribute though, but it's easy to fix

miguelb17:11:37

so looking at here: https://facebook.github.io/react/docs/react-api.html#createfactory, you’re suggesting maybe try a using React.createFactory(type)?

Niki17:11:38

for now, just use (def ^:export rumCompExp rumComp)

Niki17:11:04

no, just call rumCompExp()

Niki17:11:12

it’ll return an element

miguelb17:11:23

alright I try that, thank you!

miguelb17:11:41

and for the work, datascript and rum are why I keep trying to get clojurescript in at at work

Niki17:11:58

if you need class, something like that should work: (def ^:export rumCompClass (:rum/class (meta rumComp))

miguelb17:11:35

hmm am I missing something, if look at the rumCompExp fn and try to run it I get … not a function. In devtools it says its a cljs.core.MetaFn

miguelb17:11:26

using fighwheel with rum option

miguelb17:11:37

create-react-app as the demo app

Niki17:11:54

try with the class then

Niki17:11:02

I have no idea what MetaFn is

Niki17:11:10

usually cljs fns are directly callable

miguelb17:11:54

btw was trying to call the fn in JSX like this {rumCompExp()}

miguelb17:11:47

with class: cannot read :rum/args of undefined

Niki17:11:13

maybe it’s because export is not defined on an actual fn, but only on a def var

Niki17:11:28

ok I’ll have to investigate that then

Niki17:11:31

just had an another idea

Niki17:11:49

try (defn ^:export rumCompExp [] (rumComp)) :)

Niki17:11:10

probably MetaFn is a fn with unknown amount of arguments

Niki17:11:21

that’s why you can’t directly call it

miguelb17:11:07

ok so given this:

(def ^:export rumComp (rum/defc hello-world []
                        [:h1 (:text "hello world")]))

(defn ^:export rumCompExp [] (rumComp))

miguelb17:11:27

I get <h1></h1> in the html

miguelb17:11:49

but no text

Niki18:11:27

just

(rum/defc hello-world []
                        [:h1 (:text "hello world")]))

(defn ^:export rumCompExp [] (hello-world))

miguelb18:11:30

still empty <h1>

miguelb18:11:56

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';

const rumCompExp = window.rum_test.core.rumCompExp;

class App extends Component {
  render() {
    return (
      <div className="App">
        <div className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h2>Welcome to React</h2>
        </div>
        <p className="App-intro">
          To get started, edit <code>src/App.js</code> and save to reload.
        </p>
        {rumCompExp()}

      </div>
    );
  }
}

export default App;

Niki18:11:23

well, now it’s strange

Niki18:11:35

are you sure you have no compilation errors in figwheel?

miguelb18:11:58

let me reload the config

miguelb18:11:11

ok, that was silly error on my part

miguelb18:11:26

(:text “hello world)

miguelb18:11:51

I was trying not to use the template’s atom and just put in the string quickly

miguelb18:11:19

still compiled correctly though

miguelb18:11:42

trying to access :text on a string is valid ?

Niki18:11:18

not sure if valid or not, but certainly doesn’t make sense

miguelb18:11:33

works now : )

miguelb18:11:40

thanks again