-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
colorize code in results, simplify cell error handling,
- Loading branch information
Showing
16 changed files
with
264 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
(ns maria.cloud.local | ||
(:refer-clojure :exclude [get]) | ||
(:require [applied-science.js-interop :as j] | ||
[maria.cloud.transit :as t] | ||
[re-db.reactive :as r])) | ||
|
||
(defn local-id [id] (str "maria.local/" id)) | ||
|
||
(defn get | ||
([id] (get id nil)) | ||
([id not-found] | ||
(if-let [v (j/get-in js/window [:localStorage (local-id id)])] | ||
(t/read v) | ||
not-found))) | ||
|
||
(defn put! [id v] | ||
(j/assoc-in! js/window [:localStorage (local-id id)] (t/write v))) | ||
|
||
(defonce ratom | ||
(memoize | ||
(fn [id init] | ||
(let [v (if-let [v (j/get-in js/window [:localStorage (local-id id)])] | ||
(t/read v) | ||
::new) | ||
(let [v (get id ::not-found) | ||
!rx (r/atom v)] | ||
(add-watch !rx ::sync | ||
(fn [_ _ _ new-value] | ||
(j/assoc-in! js/window [:localStorage (local-id id)] (t/write new-value)))) | ||
(when (= v ::new) | ||
(fn [_ _ _ new-value] (put! id new-value))) | ||
(when (= v ::not-found) | ||
(reset! !rx init)) | ||
!rx)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,37 @@ | ||
(ns maria.cloud.persistence | ||
(:require [maria.cloud.github :as gh] | ||
[maria.editor.keymaps :as keymaps])) | ||
[maria.cloud.local :as local] | ||
[maria.editor.doc :as doc] | ||
[maria.editor.keymaps :as keymaps] | ||
[yawn.hooks :as h] | ||
[goog.functions :as gf])) | ||
|
||
(defn autosave-fn | ||
"Returns a callback that will save the current doc to local storage after a 1s debounce." | ||
[] | ||
(-> (fn [id ^js prev-state ^js next-state] | ||
(when-not (.eq (.-doc prev-state) (.-doc next-state)) | ||
(local/put! id (doc/doc->clj (.-doc next-state))))) | ||
(gf/debounce 1000))) | ||
|
||
(keymaps/register-commands! | ||
{:file/new {:kind :prose | ||
:bindings [:Mod-n] | ||
:f #(prn :new)} | ||
{:file/new {:kind :prose | ||
:bindings [:Mod-n] | ||
;; generate a new UUID, | ||
;; go to that (local) route, | ||
;; sync local storage for that UUID, | ||
;; if empty create a blank doc. | ||
:f #(prn :new)} | ||
:file/duplicate {:kind :prose | ||
:f #(prn :duplicate)} | ||
:file/revert {:kind :prose | ||
:f #(prn :revert)} | ||
:file/save {:kind :prose | ||
:bindings [:Mod-s] | ||
:when gh/token | ||
:f #(prn :save)}}) | ||
;; create a new gist with contents of current doc. | ||
:f #(prn :duplicate)} | ||
:file/revert {:kind :prose | ||
;; :when local state diverges from gist state. | ||
;; reset local state to gist state. | ||
:f #(prn :revert)} | ||
:file/save {:kind :prose | ||
:bindings [:Mod-s] | ||
:when gh/token | ||
;; if local, create a new gist and then navigate there. | ||
;; if gist, save a new revision of that gist. | ||
:f #(prn :save)}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.