Skip to content

Commit

Permalink
Migrate from boot -> deps.edn / clj cli
Browse files Browse the repository at this point in the history
Also bumped versions of clojure
  • Loading branch information
tkjone committed Feb 12, 2019
1 parent 80d4e4a commit d4ccab9
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 83 deletions.
3 changes: 2 additions & 1 deletion 18-string-times/README.md
Expand Up @@ -2,13 +2,14 @@

I liked this lesson because it provided an opportunity to explore how strings and numbers respond to math in Clojure.

- [Quick Start](#quick-start)
- [Multiplication and Strings](#multiplication-and-strings)

# Requirements

Please ensure you have a clojure environment running locally - see [Getting Started Guide](https://github.com/tkjone/clojurescript-30#getting-started) if you need to set one up.

# Quickstart
# Quick Start

Run the following comamnds from the root of `20-string-times`

Expand Down
14 changes: 3 additions & 11 deletions 19-unreal-webcam-fun/.gitignore
@@ -1,11 +1,3 @@
/target
/classes
/checkouts
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
/.nrepl-port
/.nrepl-history
/out
# clojure
out
.cpcache
69 changes: 39 additions & 30 deletions 19-unreal-webcam-fun/README.md
@@ -1,16 +1,31 @@
# Unreal Webcam Fun

For this one I did not add the rgb effects and only focused on showing the webcam in the video element and taking a picture. The other items have been done before and I spent more time researching more idiomatic clojure code
For this one I did not add the rgb effects and only focused on showing the webcam in the video element and taking a picture. The other items have been done before and I spent more time researching more idiomatic clojure code

* [Working with Native JS Functions](#working-with-native-js-functions)
* [Thread v. Double Dot Macro](#thread-v-dot-dot-macro)
* [Require from Google Closure](#require-from-google-closure)
* [Time Intervals](#time-intervals)
* [Add to JS Global Scope](#add-to-js-global-scope)
- [Quick Start](#quick-start)
- [Working with Native JS Functions](#working-with-native-js-functions)
- [Thread v. Double Dot Macro](#thread-v-dot-dot-macro)
- [Require from Google Closure](#require-from-google-closure)
- [Time Intervals](#time-intervals)
- [Add to JS Global Scope](#add-to-js-global-scope)

# Quick Start

Run the following comamnds from the root of `20-string-times`

**1. Run the projcet**

```bash
clj -A:dev
```

**2. Visit the app**

http://localhost:9000/

# Working with Native JS Functions

This is more of a note, but sometimes you might try to use a JS method and be confused by the fact that passing a CLJS object will not work with it. In cases like this, remember to switch to a JS object instead. For example:
This is more of a note, but sometimes you might try to use a JS method and be confused by the fact that passing a CLJS object will not work with it. In cases like this, remember to switch to a JS object instead. For example:

```clojure
(-> js/navigator
Expand All @@ -22,35 +37,31 @@ This is more of a note, but sometimes you might try to use a JS method and be co

By using the `#js` macro, I am creating and passing a JS object to `.getUserMedia`


# Thread v dot dot macro

You are going to notice that I use the `->` macro for the first time in this series. I am going to opt for this going forward. It appears to be the preferred option based on conversation I have had with other **clojurians**.

You are going to notice that I use the `->` macro for the first time in this series. I am going to opt for this going forward. It appears to be the preferred option based on conversation I have had with other **clojurians**.

# Require from Google Closure

Take a look at [this article](https://www.martinklepsch.org/posts/requiring-closure-namespaces.html) for more information.


# Time Intervals

Lets say you want to `console.log` something once every 2 seconds. To do this in JavaScript, you would use something like this:
Lets say you want to `console.log` something once every 2 seconds. To do this in JavaScript, you would use something like this:

```javascript
setInterval(() => console.log('tick'), 1000)
setInterval(() => console.log("tick"), 1000);
```

How would you achieve the same thing in clojure? Turns out there are no less than 3 approaches to this. Below, I will show examples of all three of the options, but I would say that either **option 1** or **option 2** are your best bets. `core.async` is a beast of a library to use for such a simple task.
How would you achieve the same thing in clojure? Turns out there are no less than 3 approaches to this. Below, I will show examples of all three of the options, but I would say that either **option 1** or **option 2** are your best bets. `core.async` is a beast of a library to use for such a simple task.


**1. js/setInterval**
**1. js/setInterval**

```clojure
(js/setInterval #(p "tick") 1000)
```

**2. goog.timer**
**2. goog.timer**

To use this, you need to require `goog timer` into your namespace like this:

Expand All @@ -70,12 +81,11 @@ and than you can use it like this
(.start my-timer)
```

Working with google closure can be a little confusing, so I recommend reviewing the source code when stuck. For example, when learning how to start the above timer, I reviewed [google closure timer source code](https://github.com/google/closure-library/tree/master/closure/goog/timer). Specifically, checkout `timer_test.js`.

Working with google closure can be a little confusing, so I recommend reviewing the source code when stuck. For example, when learning how to start the above timer, I reviewed [google closure timer source code](https://github.com/google/closure-library/tree/master/closure/goog/timer). Specifically, checkout `timer_test.js`.

**3. core.async**
**3. core.async**

This is the heavy duty option. To start using this approach, you have to add it to your projects dependencies. See `build.boot` for this line:
This is the heavy duty option. To start using this approach, you have to add it to your projects dependencies. See `build.boot` for this line:

```clojure
[org.clojure/core.async "0.3.443"]
Expand All @@ -102,25 +112,24 @@ Now we can make ourselves a little setInterval timer core.async style:
(recur)))
```

This last one was a little tricky to figure out how to use at all. More info on `core.async`:

* https://www.braveclojure.com/core-async/
This last one was a little tricky to figure out how to use at all. More info on `core.async`:

* http://www.bradcypert.com/clojure-async/
- https://www.braveclojure.com/core-async/

* http://rigsomelight.com/drafts/clojurescript-core-async-todos.html
- http://www.bradcypert.com/clojure-async/

* http://martintrojer.github.io/clojure/2014/03/09/working-with-coreasync-exceptions-in-go-blocks
- http://rigsomelight.com/drafts/clojurescript-core-async-todos.html

* https://github.com/swannodette/async-tests/tree/master/src/async_test
- http://martintrojer.github.io/clojure/2014/03/09/working-with-coreasync-exceptions-in-go-blocks

- https://github.com/swannodette/async-tests/tree/master/src/async_test

# Add to JS Global Scope

I only do this in this lesson because I wanted to align with wes's lesson set. Normally, this would not be the way to do it, but it is good to know how this would be done.
I only do this in this lesson because I wanted to align with wes's lesson set. Normally, this would not be the way to do it, but it is good to know how this would be done.

```clojure
(set! js/takePhoto #(...))
```

Note that the naming convention for the `takePhoto` function is not idiomatic JS. This was just done for this lesson. Remember that `lisp-case` is not commonly used in JS.
Note that the naming convention for the `takePhoto` function is not idiomatic JS. This was just done for this lesson. Remember that `lisp-case` is not commonly used in JS.
5 changes: 0 additions & 5 deletions 19-unreal-webcam-fun/boot.properties

This file was deleted.

33 changes: 0 additions & 33 deletions 19-unreal-webcam-fun/build.boot

This file was deleted.

9 changes: 9 additions & 0 deletions 19-unreal-webcam-fun/deps.edn
@@ -0,0 +1,9 @@
{:paths ["src" "resources"]
:deps {org.clojure/clojurescript {:mvn/version "1.10.516"}
org.clojure/core.async {:mvn/version "0.3.443"}}

:aliases {:dev {:main-opts ["-m" "cljs.main"
"-ro" "ro.edn"
"-w" "src"
"-c" "app.core"
"-r"]}}}
1 change: 1 addition & 0 deletions 19-unreal-webcam-fun/ro.edn
@@ -0,0 +1 @@
{:static-dir ["." "out" "resources"]}
@@ -1,7 +1,7 @@
;; create main project namespace
(ns unreal-webcam-fun.core
(ns app.core
(:require [cljs.core.async :as async])
(:require-macros [unreal-webcam-fun.macros :refer [p pp]]
(:require-macros [app.macros :refer [p pp]]
[cljs.core.async.macros :as m :refer [go]]))


Expand Down
@@ -1,5 +1,5 @@
;; create macros namespace
(ns unreal-webcam-fun.macros)
(ns app.macros)


(defmacro p
Expand Down

0 comments on commit d4ccab9

Please sign in to comment.