oakmac / oakmac/standard-clojure-style-js
add test case from Om
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 137
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Description
This is a good file / test case to add:
(ns om.transit
#?(:clj (:refer-clojure :exclude [ref]))
(:require [cognitect.transit :as t]
#?(:cljs [com.cognitect.transit :as ct])
[om.tempid :as tempid #?@(:cljs [:refer [TempId]])])
#?(:clj (:import [com.cognitect.transit
TransitFactory WriteHandler ReadHandler]
[om.tempid TempId])))
#?(:cljs
(deftype TempIdHandler []
Object
(tag [_ _] "om/id")
(rep [_ r] (. r -id))
(stringRep [_ _] nil)))
#?(:clj
(deftype TempIdHandler []
WriteHandler
(tag [_ _] "om/id")
(rep [_ r] (. ^TempId r -id))
(stringRep [_ r] (. ^TempId r -id))
(getVerboseHandler [_] nil)))
#?(:cljs
(defn writer
([]
(writer {}))
([opts]
(t/writer :json
(assoc-in opts [:handlers TempId] (TempIdHandler.))))))
#?(:clj
(defn writer
([out]
(writer out {}))
([out opts]
(t/writer out :json
(assoc-in opts [:handlers TempId] (TempIdHandler.))))))
#?(:cljs
(defn reader
([]
(reader {}))
([opts]
(t/reader :json
(assoc-in opts
[:handlers "om/id"]
(fn [id] (tempid/tempid id)))))))
#?(:clj
(defn reader
([in]
(reader in {}))
([in opts]
(t/reader in :json
(assoc-in opts
[:handlers "om/id"]
(reify
ReadHandler
(fromRep [_ id] (TempId. id))))))))
(comment
;; cljs
(t/read (reader) (t/write (writer) (tempid/tempid)))
;; clj
(import '[java.io ByteArrayOutputStream ByteArrayInputStream])
(def baos (ByteArrayOutputStream. 4096))
(def w (writer baos))
(t/write w (TempId. (java.util.UUID/randomUUID)))
(.toString baos)
(def in (ByteArrayInputStream. (.toByteArray baos)))
(def r (reader in))
(t/read r)
)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the referenced src/main/om/transit.cljc example first, then locate the repository's existing test entry point for transit handling. Add coverage corresponding to the supplied Clojure and ClojureScript reader and writer case, and confirm the test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clojure
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100