clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
2021-06-19T09:54:30.427100Z

I am not familiar with this topic even not under the context of cljs. I am writing a react-native app with clojurescript. I wonder how to support sync data between the server so that when the mobile goes offline and later online again it will sync data (either upload to the server or retrieve data from the server as another device might have updated it).

raspasov 2021-06-21T20:23:25.466Z

This is a very broad topic which I’ve been interested in for a long time. It’s a rabbit hole 🙂 . There’s also CRDTs which are a formal way to do this but the automatic, formally correct resolution of CRDT conflicts does not always match what the average person would expect to be the “correct” or “expected” end state. TLDR, conflict resolution is application-specific, in most cases. There’s no “one size fits all”.

raspasov 2021-06-21T20:28:19.466500Z

If you want to dig deep on this topic, everything by https://martin.kleppmann.com is really good. Warning: you might spend a lot of time exploring this 🙂

rickheere 2021-06-21T22:09:40.468Z

Thanks for the tip, I'll dive in. I've looked into this topic many years ago and kept my ears open from then on but the solution/answers (summed up above) I came across never satisfied me. I hope that will change

👍 1
rickheere 2021-06-19T14:05:20.427300Z

If you want to know more about this search for the term "offline first"

rickheere 2021-06-19T14:08:36.427600Z

But the big spoiler is that in the end you just have to pick a strategy on how to deal with merge conflicts.

rickheere 2021-06-19T14:13:25.428Z

There are 3 options when it comes to dealing with merge conflicts when syncing the 2 databases. Server is always right over the client, client is always right over the server or give the user some way to pick one of the 2 options

West 2021-06-19T14:32:05.428300Z

So I’m using cljs-node-io, it’s supposed to make <http://java.io|java.io>-like abstractions node.js file operations. I’m getting the same warnings while shadow compiles. This is one of 4 of the same warnings. The warning all happen when I use dot-methods from the library. For my intents and purposes this is no problem, just a bit noisy.

------ WARNING #1 - :infer-warning ---------------------------------------------
 File: /Users/main/Code/clojure/uniorg-util/src/uniorg_util/core.cljs:94:17
--------------------------------------------------------------------------------
  91 |           (let [d (io/file path)]
  92 |             (for [f (.listFiles d)]
  93 |               (when (.isFile f)
  94 |                 (.getName f))))))
-----------------------^--------------------------------------------------------
 Cannot infer target type in expression (. f getName)
--------------------------------------------------------------------------------
  95 |
  96 | (defn create-files [in-path out-path json?]
  97 |   (create-out-dir out-path)
  98 |   (let [input     (filter #(-&gt; % io/file .getExt (= ".org"))
--------------------------------------------------------------------------------

West 2021-06-19T15:24:54.428500Z

I decided to use cljs-node-io.fs instead of the methods of the type File. No more warnings. Edit: looks a lot cleaner as well

p-himik 2021-06-19T15:40:31.428700Z

For future reference: https://code.thheller.com/blog/shadow-cljs/2017/11/06/improved-externs-inference.html

p-himik 2021-06-19T15:41:23.429Z

tl;dr: add ^js in front of the definition of f. Just in case - make sure that it still works under advanced compilation with that addition.

West 2021-06-19T15:56:31.429200Z

Got it.

thheller 2021-06-19T16:06:36.429500Z

and also don't use a wrapper that tries to make it look like java. use the node methods directly. IMHO 😛

2021-06-19T16:51:19.430800Z

how do I get the namespace where a macro is called (instead of where the macro is defined)? We have *ns* in clj but not in cljs

thheller 2021-06-19T16:51:54.431500Z

you have *ns* in CLJS macros (given that they are written in CLJ)

2021-06-19T16:52:49.432300Z

but that's the ns of where the macro is defined? I am asking about where it's called

2021-06-19T16:52:56.432500Z

let me give an example

thheller 2021-06-19T16:53:18.432800Z

it is where the macro is called, not defined. *ns* is a runtime binding, which is bound to the current ns when expanding macros in the CLJS compiler. same as CLJ really.

2021-06-19T16:57:05.434500Z

thanks, let me try again

2021-06-19T17:07:02.435600Z

(ns <http://foo.app|foo.app>
  (:require [foo.macro-lib :as lib]))
  
(lib/mymacro foo)
=&gt; how to implement mymacro so that the above expands to `<http://foo.app/foo|foo.app/foo>`?

thheller 2021-06-19T17:08:44.435800Z

(defmacro mymacro [the-sym]
  (symbol (str *ns*) (name the-sym)))

2021-06-19T17:08:48.435900Z

I've tested, *ns* always return nil at run time.

thheller 2021-06-19T17:09:09.436100Z

at CLJS runtime yes, and macro-expansion time no (so CLJ compile time, there it is bound).

2021-06-19T17:12:51.436500Z

it works, thanks a lot

West 2021-06-19T19:29:02.436600Z

I think I’ll still use it for slurp and spit lol

thheller 2021-06-19T19:31:07.437200Z

FWIW (:require ["fs" :as fs]) and (fs/readFileSync path) or (fs/writeFileSync path content) would be slurp/spit equiv

West 2021-06-19T21:41:55.438200Z

I see! I’ll have to remember that for the next thing I build.

West 2021-06-19T21:44:39.439900Z

Has anybody used https://github.com/clojure/tools.cli/ for their projects? I’m considering using it for my node script here, I just need a little help with configuring some of the options. Maybe I could take a look at your project? https://github.com/wildwestrom/uniorg-util

West 2021-06-20T19:25:28.452400Z

Ok, I’m using it and I’m a bit confused as to why my tests are failing.

thheller 2021-06-20T19:32:50.452600Z

args will be a seq of strings, so not one string but many. so ["-e" "-m"] instead of "-e -m"

thheller 2021-06-20T19:35:11.452800Z

don't know why you are checking true?. that doesn't seem to be the expected result?

West 2021-06-20T19:54:43.453100Z

I wanted this option to return true or false that’s why I check it that way.

West 2021-06-20T19:54:56.453300Z

But that makes sense, no wonder it won’t work.