This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-02
Channels
- # aleph (3)
- # announcements (2)
- # babashka (4)
- # beginners (74)
- # calva (21)
- # clj-kondo (30)
- # cljs-dev (7)
- # cljsrn (42)
- # clojure (121)
- # clojure-dev (13)
- # clojure-europe (23)
- # clojure-losangeles (2)
- # clojure-nl (2)
- # clojure-norway (7)
- # clojure-spec (140)
- # clojure-uk (58)
- # clojuredesign-podcast (9)
- # clojurescript (49)
- # clojutre (2)
- # cursive (32)
- # datascript (2)
- # datomic (59)
- # duct (7)
- # figwheel-main (6)
- # fulcro (18)
- # graphql (5)
- # jackdaw (1)
- # joker (6)
- # juxt (7)
- # leiningen (9)
- # off-topic (1)
- # pedestal (14)
- # quil (2)
- # re-frame (3)
- # reitit (8)
- # shadow-cljs (78)
- # sql (8)
- # timbre (3)
- # vim (69)
Can I use requestIdleCallback to schedule cpu intensive tasks? https://developers.google.com/web/updates/2015/08/using-requestidlecallback (includes a polyfill) https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback https://caniuse.com/#feat=requestidlecallback (doesn't talk directly about JavaScriptCore)
Let me rephrase. Anyone using requestIdleCallback to schedule cpu intensive tasks?
I'd say no. only if you can break that work up into many small pieces that each take no longer than 4ms or so (it still runs in the main thread)
second @thheller yeah the key is splitting up things into very tiny bits. Looking forward to React 17 etc, the thing to use might be the react scheduler, which has a bunch of different priorities, and will fit the work around rendering.
cpu intensive work should probably be done in workers but no clue how react-native handles that
there’s no support for workers in vanilla react native. There’s some ugly hacks involving webviews, and a couple of npm libs, but none of which I’d feel comfortable relying on
I’ve been using the reframe event queue to dispatch background events, suitably batched
@olivergeorge I know people have used web workers to offload cpu intensive tasks in RN.
I guess if the work is hard but the deserialization / serialization is a small cost in comparison to the work done
@vikeri have you got any examples?
Yeah I don’t think web workers helps me in this case because of the serialization cost. Happily I can do small steps with this one.
Thanks for the replies though. I am reassured that I’m on the right path.
ah yeah, I remember seeing that, great idea putting all the subs in a worker
Web workers "structured cloning" sounds interesting. Does it generally work with CLJS data types?
Ah, well. Can't have nice things I guess.
@thheller I'm trying to set up some node tests for my react-native project. shadow-cljs.edn
...
:builds
{:app
{:target :react-native
:init-fn
:output-dir "app"
:devtools {:autoload true}}
:test
{:target :node-test
:output-to "out/node-tests.js"
:autorun true}}}
test file
(ns time-align-mobile.handlers-test
(:require [cljs.test :as t :refer-macros [deftest is]]
[time-align-mobile.handlers :as handlers]
[time-align-mobile.db :as db :refer [app-db]]))
(deftest initialize-db
(is (= app-db (handlers/initialize-db [] []))))
...
The tests are on pure clojure functions that I use in re-frame handlers. No react-native specific things in them.
But when I try to run the tests I get
>> node out/node-tests.js
SHADOW import error /home/justin/projects/time-align-mobile/.shadow-cljs/builds/test/dev/out/cljs-runtime/shadow.js.shim.module$react_native.js
/home/justin/projects/time-align-mobile/node_modules/react-native/Libraries/Utilities/warnOnce.js:15
const warnedKeys: {[string]: boolean} = {};
^^^^^^^^^^
SyntaxError: Missing initializer in const declaration
at Module._compile (internal/modules/cjs/loader.js:721:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/home/justin/projects/time-align-mobile/node_modules/react-native/Libraries/react-native/react-native-implementation.js:14:18)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
Am I doing something dumb or is there something wrong with how shadow is including other project dependencies?@jgoodhcg this isn't shadow-cljs at all. this happens if you require("react-native")
in node
.
Hmm so a node module build config that uses jest to run tests. I'll give this a try.
What I was going for was the specific node-test
build configuration that could run while I'm developing. It was only supposed to test pure cljs functions that should be able to run on node.
they are written in typescript or flow or some other JS flavor that can't be loaded directly
if you don't require any of the react-native
packages then :node-test
should be fine
I assumed that if everything up the dependency tree from the functions I imported didn't touch any react native libraries it would just work.
.../.shadow-cljs/builds/test/dev/out/cljs-runtime/shadow.js.shim.module$react_native.js
this file is generated if you did (:require ["react-native" ...])
somewhere
I thought I was clear of any react-native deps which lead me to think that shadow did something i wasn't aware of.
I'll probably try to isolate the functions I want to test this way and then come back around to a jest implementation when I go to test view components and more react-native integrated code.
Guys, sorry for bothering but I'm sick off warnings in my console window, they all have same text
Cannot infer target type in expression ...
, here is an example:
------ WARNING #17 - :infer-warning --------------------------------------------
File: D:\Dev\clojure\rn-rf-shadow\src\main\example\views\warehouse.cljs:43:43
--------------------------------------------------------------------------------
40 |
41 | (defn render-fn [item index separator]
42 |
43 | [c/text (str (.-name item) ", amount: " (.-amount item))])
-------------------------------------------------^------------------------------
Cannot infer target type in expression (. item -amount)
Can you please explain me what does it mean in other words? And how to get rid of it?