Skip to content

Commit

Permalink
add on-page-touch; bump 0.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Dec 19, 2018
1 parent 728913b commit 7fbde97
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 7 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ Cumulo Util (WIP)
[![Clojars Project](https://img.shields.io/clojars/v/cumulo/util.svg)](https://clojars.org/cumulo/util)

```edn
[cumulo/util "0.1.4"]
[cumulo/util "0.1.5"]
```

Notice that you will need `shortid` in your project since it's depended on:

```bash
yarn add shortid
```

```clojure
Expand All @@ -19,6 +25,7 @@ Cumulo Util (WIP)
(cumulo-util.core/unix-time!)
(cumulo-util.core/repeat! 1 #(println "doing")!) ; in seconds
(cumulo-util.core/delay! 1 #(println "done")!) ; in seconds
(cumulo-util.core/on-page-touch (fn [] (println "touched")))

(cumulo-util.file/write-mildly! "a.text" "content")
(cumulo-util.file/get-backup-path!)
Expand Down
249 changes: 249 additions & 0 deletions calcit.edn

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion meyvn.edn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{:pom {:group-id "cumulo",
:artifact-id "util",
:version "0.1.4",
:version "0.1.5",
:name "Util functions for Cumulo projects"}
:packaging {:jar {:enabled true
:remote-repository {:id "clojars"
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
},
"author": "jiyinyiyong",
"license": "MIT",
"dependencies": {},
"dependencies": {
"shortid": "^2.2.14"
},
"devDependencies": {
"shadow-cljs": "^2.7.9",
"source-map-support": "^0.5.9",
Expand Down
15 changes: 11 additions & 4 deletions shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
"clojars" {:url "https://mirrors.ustc.edu.cn/clojars/"}}
:open-file-command ["subl" ["%s:%s:%s" :file :line :column]]
:builds {:app {:target :node-script
:output-to "target/app.js"
:main cumulo-util.app/main!
:devtools {:after-load cumulo-util.app/reload!}
:release {:output-to "dist/app.js"}}}}
:output-to "target/app.js"
:main cumulo-util.app/main!
:devtools {:after-load cumulo-util.app/reload!}
:release {:output-to "dist/app.js"}}
:client {:target :browser
:output-dir "target/"
:asset-path "./"
:modules {:client {:init-fn cumulo-util.client/main!}}
:devtools {:after-load cumulo-util.client/reload!
:http-root "target"
:http-port 7000}}}}
6 changes: 6 additions & 0 deletions src/cumulo_util/client.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

(ns cumulo-util.client (:require [cumulo-util.core :refer [on-page-touch]]))

(defn main! [] (on-page-touch (fn [] (println "called"))))

(defn reload! [] )
13 changes: 13 additions & 0 deletions src/cumulo_util/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@

(defn id! [] (.generate shortid))

(defn on-page-touch [listener]
(let [*cooling (atom false)
call-listener (fn []
(when (not @*cooling)
(listener)
(reset! *cooling true)
(delay! 0.8 #(reset! *cooling false))))]
(.addEventListener js/window "focus" (fn [event] (call-listener)))
(.addEventListener
js/window
"visibilitychange"
(fn [event] (when (= "visible" (.-visibilityState js/document)) (call-listener))))))

(defn repeat! [duration task] (js/setInterval task (* 1000 duration)))

(defn unix-time! [] (.valueOf (js/Date.)))
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@ mkdirp@^0.5.1:
dependencies:
minimist "0.0.8"

nanoid@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-2.0.0.tgz#e1ab4a4b024a38d15531ba34a712a201540de639"
integrity sha512-SG2qscLE3iM4C0CNzGrsAojJHSVHMS1J8NnvJ31P1lH8P0hGHOiafmniNJz6w6q7vuoDlV7RdySlJgtqkFEVtQ==

node-libs-browser@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/node-libs-browser/-/node-libs-browser-2.1.0.tgz#5f94263d404f6e44767d726901fff05478d600df"
Expand Down Expand Up @@ -534,6 +539,13 @@ shadow-cljs@^2.7.9:
which "^1.3.1"
ws "^3.0.0"

shortid@^2.2.14:
version "2.2.14"
resolved "https://registry.yarnpkg.com/shortid/-/shortid-2.2.14.tgz#80db6aafcbc3e3a46850b3c88d39e051b84c8d18"
integrity sha512-4UnZgr9gDdA1kaKj/38IiudfC3KHKhDc1zi/HSxd9FQDR0VLwH3/y79tZJLsVYPsJgIjeHjqIWaWVRJUj9qZOQ==
dependencies:
nanoid "^2.0.0"

source-map-support@^0.4.15:
version "0.4.18"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.18.tgz#0286a6de8be42641338594e97ccea75f0a2c585f"
Expand Down

0 comments on commit 7fbde97

Please sign in to comment.