Fork me on GitHub
#clojurescript
<
2019-12-01
>
ec14:12:14

Im trying to use slatejs with reagent

const App = () => {
  const editor = useMemo(() => withReact(createEditor()), [])

  // Define a rendering function based on the element passed to `props`. We use
  // `useCallback` here to memoize the function for subsequent renders.
  const renderElement = useCallback(props => {
    switch (props.element.type) {
      case 'code':
        return 
      default:
        return 
    }
  }, [])

  return (
    
       {
          if (event.key === '&') {
            event.preventDefault()
            editor.exec({ type: 'insert_text', text: 'and' })
          }
        }}
      />
    
  )
}

const CodeElement = props => {
  return (
    
      {props.children}
    
) } const DefaultElement = props => { return

{props.children}

}
CLJ version
(defn codeElem [props]
  [:pre  (.-attributes props) [:code (.-children props)]])

(defn default [props]
  [:p (merge nil (:attributes props)) (:children props)])

(defn renderElem [props]
  (r/create-element 
   (r/reactify-component 
    (if (= (-> props .-element .-type) "code") codeElem default))
   props))

(defn editor-panel []
  (let [ed (withReact (createEditor))]
    (fn []
      [:div#editor 
       [:> Slate {:editor ed :defaultValue defaultValue}
        [:> Editable 
         {:onKeyDown #(println (.-key %))
          :renderElement renderElem}]]])))
But getting strange errors on console, how can I convert that to reagent?

royalaid17:12:06

Hey all, I am just curious if there is CLJS refactor support for emacs in someway? Poking around it doesn't seem like that is the case.

dpsutton17:12:59

there isn't to my knowledge. clojure-lsp handles this just fine however. https://github.com/snoe/clojure-lsp

walterl19:12:06

Hi everyone! 👋 I'm following the quick start tut (https://clojurescript.org/guides/quick-start), but I'm not getting a REPL when running clj --main cljs.main --compile hello-world.core --repl. It downloaded all the deps, opened the browser, and printed Hello world! in the terminal, but some minutes later it still hasn't showed a REPL prompt.

walterl19:12:36

I'm on Ubuntu, and just installed clj et al

walterl19:12:50

Any ideas?

walterl20:12:14

This did it (from http://clojure.2344290.n4.nabble.com/I-did-the-Clojurescript-quickstart-repl-prompt-never-shows-up-tp18363p18364.html): clj --main cljs.main --compile hello-world.core --repl --repl-opts "{:launch-browser false}"

borkdude21:12:49

what's the meaning of *out* in CLJS, it seems it's not used for anything at all?

thheller21:12:02

it is provided as a binding to match clojure I guess. it is used by cljs.pprint

borkdude21:12:50

so instead of rebinding out, the common idiom in cljs is setting *print-fn* right?

thheller21:12:36

messing with *print-fn* should really be avoided since it interferes with tools

thheller21:12:53

bindings suck in an async context

borkdude21:12:13

so the only primitive that should really be used is with-out-str maybe?

borkdude21:12:33

well, that also rebinds *print-fn* so I don't know why that would be an exception?

thheller21:12:25

you can set it ... its just dangerous when doing async stuff

borkdude21:12:41

ok, so as long as the action in the middle is sync, it should be fine

thheller21:12:28

better yet use pr-str that bypasses the binding completely I think