This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-14
Channels
- # aleph (1)
- # announcements (1)
- # beginners (59)
- # boot (2)
- # calva (5)
- # cider (8)
- # clj-kondo (6)
- # cljdoc (5)
- # cljsrn (11)
- # clojure (123)
- # clojure-dusseldorf (1)
- # clojure-europe (4)
- # clojure-italy (22)
- # clojure-losangeles (4)
- # clojure-nl (10)
- # clojure-spec (18)
- # clojure-uk (22)
- # clojurescript (103)
- # cursive (32)
- # data-science (1)
- # datomic (21)
- # events (2)
- # figwheel (1)
- # fulcro (12)
- # graalvm (3)
- # graphql (8)
- # jobs (2)
- # kaocha (4)
- # klipse (2)
- # lein-figwheel (4)
- # leiningen (23)
- # off-topic (11)
- # planck (11)
- # re-frame (8)
- # reagent (2)
- # reitit (3)
- # rewrite-clj (1)
- # ring (1)
- # ring-swagger (31)
- # schema (2)
- # shadow-cljs (66)
- # spacemacs (3)
- # specter (16)
- # sql (9)
- # tools-deps (16)
- # vim (26)
Does JS and/or ClojureScript provide a way to restrict oneself to exact integer arithmetic, i.e. wrapping or exceptions are OK, but auto-promoting to floating point numbers is not?
VM of course attempt to do integer arithmetic for performance and we rely on that - but there's no way to do anything that wouldn't damage perf
So even all the JS stuff like (num | 0) doesn't prevent arithmetic ops from promoting to floats?
I think AppleSoft BASIC was the last language I used that did that. Maybe Perl, I guess.
People that implement bignum arithmetic libs in JS are just really careful with their arithmetic expressions I guess?
could have probably done things that way in the beginning but probably would have needed to do a lot of stuff to recover perf
but time has shown it to be a very low value add for most users - JavaScript thus ClojureScript aren't used much for numerics
makes sense. Just trying to familiarize myself with the differences. Thx for the quick info.
It's a fundamental JS issue - so if / when it gets sorted out there - we'll probably follow along
I asked this here before but I'm going to ask again in hope to get some more input: Does anyone have experience with embedded databases in ClojureScript (Electron)? I'm trying to figure out what I'd best use for a small amount of entities with few relations but possibly a lot of datapoints/rows for each entity. I want the data to be persistent on the users computer and don't want that the user needs to install additional tools (ex. MongoDB). My current contestants I found are: LevelDB (Through LevelUp), Sqlite3 (embedded) and NeDB (embedded MongoDB-like DB). Any experience report / suggestions / inputs are welcome 🙂
There’s IndexedDB backed by SQLite, built into Chrome so you can use that without installing additional modules
indexeddb yes, I’m not aware of existing implementations of full text search for it unfortunately
Here’s an interesting read regarding this topic https://hacks.mozilla.org/2014/06/breaking-the-borders-of-indexeddb/
Ah this looks interesting. Thanks for the read! I guess I may also consider to use Dexie.js
directly as it implements certain features out of the box.
There's https://pouchdb.com/ I haven't used it but it may help.
@UCMNZLJ93 that looks actually very useful and there seem to be text search extensions for it. It might also allow to make support for datasync accross devices easy.
What I'm curious about is how can we sync it with PostgreSQL backend.
And if we can't, wouldn't it be better to use Dexie.js
.
I dont really think it makes a difference in that case. With both, Dixie and Pouchdb we would have to program the sync ourselves and transport from key/value stores to Postgres or any SQL db. Unless I miss some aspect.
Dexie is lighter than Pouchdb, but in the end it depends on requirements and features. Pouchdb probably have more features.
Maybe yes. But I also think that Pouchdb might have better community support than Dexie. I just now remembered that the Meteor.js framework uses a Browser integrated Database too. https://www.npmjs.com/package/minimongo might be worth a glimpse.
Lovefield is developed using Closure Library: https://github.com/google/lovefield
@UCMNZLJ93 thanks! It looks very interesting and seems to have quite some traction looking at the github stars. Ill dig into it a bit
This seems probably best option to me, I'll be glad to listen feedback on it from you.
AFAIK Lovefield is used in GMail
you can confirm this by searching for lovefield
in sources with gmail open
https://github.com/google/lovefield/blob/master/docs/FAQ.md#is-lovefield-production-quality It's mentioned in FAQ too.
I think I'll give lovefield a shot! I might first have to write a small wrapper though 🙂 not sure how long it takes me to get going given my adept status in CLJ 😄
I did give lovefield a shot and also began writing a (very small) wrapper for it but I soon noticed some things:
• While I found about all things I needed, the documentation is still quite confusing
• Lovefield assumes only one connection at a time to the database which is fine for my kind of app but often falls short in the web environment (PouchDB has concurrency support integrated):
>Lovefield assumes that at a given time, there is only one connection to a database instance. By design the tuple (origin, schema name, version) uniquely identify a database instance on data store. If there are multiple pages or tabs connected to the same database, there can be a problem of data inconsistency. Users shall be aware of this problem and plan accordingly.
• Lovefield has no sync protocols (except Firebase) like PouchDB.
• Lovefield has no support for attachments - This can maybe be worked around in a wrapper - PouchDB would have this integrated though.
• Lovefield builds typed tables upon the untyped indexeddb and works extensively with versions/upgrades (Or shall I say migrations) and brings relational SQL-like convenience to the Web-World. This is nice for when its needed - I noticed that this is overkill for me and makes it harder to deal with my data where a No-SQL design fits perfectly well.
• Lovefield needs a connection created asynchronously to be able to access the database where PouchDB gives us an instant db object to work with. Latter makes it simpler to use as we do not have an initial time in which no requests are allowed. I believe a simple workaround to this would be to use a promise-chan
async channel in place of the db object of lovefield and access the channels value in a query-wrapper before making the requests - i'm not so sure if thats a good idea though.
These are some points which popped up for me until now - not sure if there will be any more as I lean towards giving PouchDB a shot due to the points listed
I could work around most of the shortcomings of LoveField I see - but I don't believe its worth my time for now
I should maybe add that I'd like to implement text-search features at some point which might make a difference
how can I start a repl-env such that I can run (cljs.repl/-evaluate repl-env "<NO_SOURCE_FILE>" 1 "console.log('hi');")
?
You want to evaluate that as a Clojure/Java expression?
Because in my quick tries in a Node-based REPL evaluating ClojureScript expressions, there is no cljs.repl/-evaluate defined at all.
With a deps.edn file that contains only this line: {:deps {org.clojure/clojurescript {:mvn/version "1.10.520"}}}
I can run clj
command from terminal, get a Clojure/Java REPL user=> prompt, and at least (require 'cljs.repl)
followed by (doc cljs.repl/-evaluate)
, and it exists. I do not know what arg to pass for repl-env to do something useful with that.
Hello! Can I get js array element by index in more js-y way, than (-> arr js->clj first)
? Js arrays have not get
or at
magic methods, but I dont know how to use []
in cljs interop 🙂
(aget arr idx)
in fact you can use nth
(nth #js [1 2] 1)
as well as first
JS Array to be precise
How can i force the execution order of these three things in clojurescript world? The second one is blocking (right now testing with js/timeout for some ms):
:on-click (fn []
(reset! updating? true)
(edit-complete-handler-fn @updated-value)
(reset! updating? false))
@dpsutton right now:
(fn [] (timeout (reset! edit-mode? false) 3000))
but it will have a real implementation laterhmm, that fixed the dialogbox immediately closing, but updating?
ratom is not changing the actual button to "disabled"
they are different ones. edit-mode
is local to parent component, setting it true
opens up dialog, the`on-click` handler is in "update" button of dialog. I wanted to disable the button while it is updating, so updating?
is component local for the dialog (not the parent component). What needs to be done for "updating" is handled by the parent, thus edit-complete-handler-fn
is a callback to parent with the updated value
I guess I could just skip setting udpating?
to false as well since the dialog is going to go away once the value is updated
(reset! updating? true) ;; disables button
(edit-complete-handler-fn @updated-value)
(reset! updating? false) ;; reenables button?
is this true?yes, but edit-complete-handler-fn
takes 2 seconds to complete (js/timeout), it should have disabled it and then in 2 seconds enable it but it is async so both get fired before the actual handler function is completed.
For now I think i can skip the last expression altogether.
how can i make that function to take 2 seconds? sort of like (Thread/sleep 2000)
in java/clojure ?
on-click (fn []
(reset! updating? true)
(js/setTimeout (fn [] (reset! updating? false)) 2000))
Callbacks should work and all the other things mentioned@neupsh exactly this .. you have to call your second reset fn in the callback of your middle event that is supposed to take some time .. remember that js is single threaded and non blocking .. which means it’ll never wait for anything 😊🙌:skin-tone-3:
I was doing this before, but I needed it only for test. I wanted to put the delay in the function that I was calling not on the caller
@neupsh You can still put the delay in the other function - but you'd have to pass a callback over to it with what you want to do after:
(defn some-other-func [cb]
(js/setTimeout
(fn []
(do-something-after-time-elapse)
(cb)) ;; The callback is called here
2000))
;; .....
(reset! updating? true)
(some-other-func #((reset! updating? false))) ;; Pass the callback
@U6JS7B99S yes, that is what I was trying to avoid 🙂
Anyone know why Clojure keeps 0.0
as 0.0
, but CLJS changes it to 0
?
In ClojureScript, numbers that happen to be integers are rendered as such. (ClojureScript uses the one JavaScript numeric type.)
Thanks, seems tricky when sending double
s from server only to have them come back as non-doubles that need to be coerced.
Well, what I'm saying is that, in ClojureScript, they are all effectively double
s even if they print like integers.
I think that js just has “number” there aren’t integers at all. So js doesn’t (and cant) distinguish an integer zero from a float zero
Right. The specific thing I'm wondering about: Does JavaScript specify how numbers are rendered, thus causing the console and all of the JavaScript REPLs above to print zero as 0
.