Skip to content

Instantly share code, notes, and snippets.

View janherich's full-sized avatar

Jan Herich janherich

View GitHub Profile
@janherich
janherich / message.edn
Last active July 12, 2017 16:36
duplicate message keys
{:message /confirmation-code ,
:command {:command {:description Confirmation code,
:sequential-params true,
:color #7099e6,
:name confirmation-code,
:params [{:name code, :type number}],
:type :response,
:has-handler false,
:hidden? nil,
:owner-id console},
@janherich
janherich / status-im.db.cljs
Last active July 24, 2017 16:46
Database denormalisation
;; Subset of current db structure
{:chat-animations
{"console"
{:parameter-box
{:height 300
:changes-counter 17}}}
:chat-loaded-callbacks
{"console" nil
"wallet" nil
"mailman" nil
@janherich
janherich / realm.cljs
Last active July 30, 2017 06:04
How to perform realm schema changes with optional database migrations
;; While working on the status-react codebase, from time to time, some properties of persisted objects
;; can be added/removed, their semantics can change, or whole new kind of objects need to be persisted
;; (or deleted).
;; In such situation, realm database schema need to be changed and maybe, even migration/s need to be specified.
;; Lets suppose we need to add boolean property `:unremovable?` to all chat objects persisted in realm.
;; First, we need to add new schema to schemas defined in accounts:
(ns status.im.data-store.realm.schemas.account.core
(:require [status.im.data-store.realm.schemas.account.v1.core :as v1]
;; all the other versions between v1 and v(N)
;; require your v(N+1) schema file, in this case, v11
(when (get contacts from)
(some->> (:data payload)
(filter (comp discovery-exists? :message-id))
(reduce (fn [fx discover]
...)
{})))
@janherich
janherich / event.clj
Created February 19, 2018 14:18
Pure event
(handlers/register-handler-fx
:delete-chat
[re-frame/trim-v]
(fn [cofx [chat-id]]
(-> (chat.models/remove-chat cofx chat-id)
(update :db navigation/replace-view :home))))
@janherich
janherich / response.clj
Last active March 21, 2018 10:53
response.clj
[{:id "0f7c65277f916ff4379fe520b875082a56e587eb3ce1c1567d9ff94206bdb05ba167c52272f20f634cd1ebdec5d9dfeb393018bfde1595d8e64a717c8b46692f", :name "Geth/v1.7.3-stable/linux-amd64/go1.9.2", :caps ["eth/62" "eth/63" "les/1" "les/2" "shh/5"], :network {:localAddress "172.20.10.6:51863", :remoteAddress "51.15.54.150:30303"}, :protocols {:shh "unknown"}} {:id "12d52c3796700fb5acff2c7d96df7bbb6d7109b67f3442ee3d99ac1c197016cddb4c3568bbeba05d39145c59c990cd64f76bc9b00d4b13f10095c49507dd4cf9", :name "Geth/v1.7.3-stable/linux-amd64/go1.9.2", :caps ["eth/62" "eth/63" "les/1" "les/2" "shh/5"], :network {:localAddress "172.20.10.6:51860", :remoteAddress "51.15.63.110:30303"}, :protocols {:shh "unknown"}} {:id "482484b9198530ee2e00db89791823244ca41dcd372242e2e1297dd06f6d8dd357603960c5ad9cc8dc15fcdf0e4edd06b7ad7db590e67a0b54f798c26581ebd7", :name "Geth/v1.7.3-stable/linux-amd64/go1.9.2", :caps ["eth/62" "eth/63" "les/1" "les/2" "shh/5"], :network {:localAddress "172.20.10.6:51859", :remoteAddress "51.15.75.138:30303"}, :protoco
@janherich
janherich / example.clj
Last active April 20, 2018 06:23
Extension - events
;; examples of public functions provided by us
(defn add-http-request [{:keys [url method payload]}]
(fn [_]
{:http {:method method
:url url
:payload payload}}))
(defn set-in [{:keys [path value]}]
(fn [_]
{:db (set-in db path value)}))
@janherich
janherich / current_situation.clj
Last active May 29, 2018 22:40
Current situation
;; All our model functions adhere to simple interface, taking any number of arguments,
;; but always the `:cofx` map as an last argument and producing map of effects (or nothing)
;; as result:
(defn effects-fn [arg1 arg2 {:keys [db] :as cofx}]
{:db (update db :some-key arg1)
:http-call ...})
;; We have both `merge-fx` macro and `merge-effect` functions at our disposal
;; Whenever we do static merging of effects, we use the former:
(defn final-effects-fn [cofx]
@janherich
janherich / functional_proposal.clj
Last active May 30, 2018 12:40
Purely functional proposal
;; Rather then relying on macros, I propose to have `merge-fx` helper exposed as function
;; taking variable number of arguments (where the first one is always cofx, second one could
;; be initial effects map and then variable number of effects producing functions, with the
;; all of them with the same form as now:
(defn effects-fn [arg1 arg2 {:keys [db] :as cofx}]
{:db (update db :some-key arg1)
:http-call ...})
(defn final-effects-fn [cofx]
(merge-fx cofx
{meta {:name "Collectibles"
:description "Demonstration of collectible command"
:documentation ""}
views/preview
(let [{{{symbol :symbol token :token tx-hash :tx-hash} :params} :content outgoing :outgoing timestamp-str :timestamp-str} @properties]
(let [collectible-token (query [:get-collectible-token symbol token])]
[view {:flex-direction :column
:align-items :flex-start}
[nft-token collectible-token]