Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow is all you need #13

Merged
merged 28 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
22fb756
new pstate for all the node-ids
sid597 May 5, 2024
72cfaec
performant panning and zooming after using missionary, still a few th…
sid597 Jun 18, 2024
9078bab
no overflow
sid597 Jun 18, 2024
16ceac2
smooth move, selection by pointer and moving around that works great
sid597 Jun 19, 2024
8047d23
server nodes
sid597 Jun 19, 2024
5a3f781
update rama
sid597 Jun 20, 2024
9b93a56
use pstate with ids only so that we only rerender on the node add del…
sid597 Jun 20, 2024
2cf199f
--amend
sid597 Jun 20, 2024
2941396
update server only when the action is done, this is optimising for I …
sid597 Jun 20, 2024
3c579bf
don't update on click only when mouse move while being clicked but I …
sid597 Jun 24, 2024
0c4e314
finally learned to get started with missionary, also maybe found the …
sid597 Jul 1, 2024
08dd187
Finally working, listen to mouse event, throttle and then update the …
sid597 Jul 1, 2024
e5a5308
client reading from global flow
sid597 Jul 3, 2024
80a4374
throttle server data by 3k, this works fine but there is discrepency …
sid597 Jul 3, 2024
0cf445f
removed inconsistencies between server and client events after using …
sid597 Jul 4, 2024
7b9865d
edges also update based on the flow
sid597 Jul 8, 2024
73314cb
- debounce for server events, debounce produces after the burst not l…
sid597 Jul 10, 2024
dee0a55
working edges
sid597 Jul 10, 2024
e087f11
finally fixed the bug which caused the nodes to jump after moving. It…
sid597 Jul 11, 2024
bf34de9
image support
sid597 Jul 11, 2024
d4d0da3
image imported after compression
sid597 Jul 12, 2024
c7232b6
refactor actions to seperate fn, svg buttons and rotate image
sid597 Jul 13, 2024
e892ead
show image on top
sid597 Jul 15, 2024
f420af0
add support for llm call and response update
sid597 Jul 24, 2024
f2f6881
update rama, send request to llm, get response, save it.
sid597 Jul 24, 2024
650e6d4
update rama
sid597 Jul 24, 2024
bb19d27
create a update event, and save it in local so as to persist and get …
sid597 Jul 24, 2024
d19b96b
create rect
sid597 Jul 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
org.clojure/tools.logging {:mvn/version "1.2.4"}
ch.qos.logback/logback-classic {:mvn/version "1.2.11"}
datascript/datascript {:mvn/version "1.5.2"}
com.rpl/rama {:mvn/version "0.12.1"}
com.rpl/rama {:mvn/version "0.17.0"}
com.rpl/rama-helpers {:mvn/version "0.9.3"}
com.rpl/specter {:mvn/version "1.1.4"}
net.clojars.wkok/openai-clojure {:mvn/version "0.14.0"}
image-resizer/image-resizer {:mvn/version "0.1.10"}
clj-http/clj-http {:mvn/version "3.12.3"}
io.github.nextjournal/clojure-mode {:git/tag "v0.3.0" :git/sha "694abc7"}
org.apache.logging.log4j/log4j-slf4j2-impl {:mvn/version "2.23.1"}}
:aliases {:dev {:extra-paths ["src-dev"]
Expand Down
13 changes: 12 additions & 1 deletion resources/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Softland</title>
<style>
html, body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
background: beige;
color: white;
overflow: "hidden";
}
</style>
</head>
<body style="margin: 0px; background: beige; color: white;">
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<script type="text/javascript" src="$:hyperfiddle.client.module/main$"></script>
</body>
Expand Down
225 changes: 225 additions & 0 deletions src/app/client/learn_missionary.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
(ns app.client.learn-missionary)



;; - Flow:
;; ?< ?= ?> latest none relieve sample
;;
;; - Discrete:
;; ap buffer eduction group-by observe recudcions seed subscribe zip
;; reduce
;;
;; - Continious
;; cp watch
;;
;; - Task:
;; ? absolve attempt compel join race rdv sleep sp timeout via
;;
;; - function:
;; ! ?! ?? blk cpu dfv mbx sem
;;
;; - form:
;; amd amb= amb>
;;
;; - body
;; holding
;;
;; - publishers:
;; memo stream signal publisher


;; Create a task

;; Task is async by nature.
(comment
(m/sleep 2)
(m/sp (println "Is this a task?"))
(m/sp 10))

;; https://claude.ai/chat/73c373ad-f3d6-4fec-ad57-d80635664d7e

;; Run a task

(comment
(m/? (m/sleep 2))
(m/? (m/sp (println "Is this a task?")))
(m/? (m/sp 10)))


;; Create a flow

;; A process able to produce arbitrary number of values before terminating. Async under the hood.
;; Build a flow from
;; a collection

(comment
(m/seed (range 10))
(m/seed [1 2 3 4 5]))

;; This will emit the values its being passed, now we can convert the values to a task and then read it.
;; We can also use ap which is similar to sp.
;; sp
;; - Used to create a task
;; - Used to wrap code to make it sequential. i.e sequential composition. You can make tasks and then
;; sequence them in bigger scope.

;; ap
;; - Used to create a flow
;; - Can be used to make sequential flow just like sp, but it has more it can be used to create. sequential process
;; - Ambiguous evaluation. ambiguous process

;; Read values from a flow

(comment
(->> [1 2 3]
(m/seed) ;; Convert the collection to a flow
(m/?>) ;; For each of the result in collection take it and continue with rest of calculation.
(println) ;; This is where the action will happen
(m/ap) ;; Wrapper for the ambiguous process
(m/reduce conj) ;; Converting the flow to a task
(m/?))) ;; Run the task, from my understanding this is the place which tells the process to run and turn
;; into a program (running instantiation of a process)
;; AM I understanding it correctly? This make it seem that ap is lazy and so is seed, they don't produce until called?
;; The doc says `cp` is lazy and only works when called
(comment
(->> [1 2 3]
(m/seed) ;; Convert the collection to a flow
(m/?<) ;; For each of the result in collection take it and continue with rest of calculation.
(println) ;; This is where the action will happen
(m/cp)))


;; Wonder if this is it do I have to convert a flow value in to a task and then be able to read its value or do stuff
;; with it in clojure??
;; Lets test it out without the fork, what can I remove and still be able to run the code

(comment
(->> [1 2 3]
(m/seed) ;; Convert the collection to a flow
(m/reduce conj) ;; Converting the flow to a task
(m/?)))


;; So this is how to obtain the result from a flow, use some function that will output values of the flow.
;; Once you have a value you convert it to a task and run the task to get the final value ???

;; Now I wonder how the reduce is doing it? Can I remove the reduce and read only one value of the code?
(comment
(->> [1 2 3]
(m/seed) ;; Convert the collection to a flow
;; So I can't continue with the following, if I have to get the value of the flow.
;; I mean this is to say we just have a bunch of values. what do you want to do with them how would the flow know?
;; so It just outputs the seed function which is correct. It is upto me what I want to do with the values.
;; Do I want to aggregate them and return the original seed? can do that using (reduce conj )
;; Do I want to take another action for each of the values? then we can fork each of the value mold each value and
;; perform the action for all the values in the flow.
;; DO I want to halt the current flow when new value is available? Drop the current evaluation of the flow value
;; and work on the latest one because the old one is not of value to us anymore. This is what we call relieving
;; backpressure (I think).
;; Or another strategy on what to discard is based on some time, so say "I want only the last value of all the values
;; that were put out in the last `x` duration". We can do that using debounce.
;; ~~Another thing we can do is to do some concurrent operations on a value, say for each value I want to do something
;; in the frontend and something in the backend.~~ WE can use ?> to fork the current evaluation context (I think value)
;; from the flow. I understood wrong what is meant by concurrent here, by concurrent it means how many computations
;; to do in parallel? i.e how many threads to spawn? each thread will take 1 value from the branch and then work on it.
(m/sp)
(m/?)))

(comment
;; One at a time.
(m/? (m/reduce conj (m/ap
(let [v (m/?> (m/seed [1 2 3]))]
(println "v1" v)
(println "v2" v)))))
;; Concurrently
(m/? (m/reduce conj (m/ap
(let [v (m/?> 3 (m/seed [1 2 3 4 5 6 7]))]
(println "v" v))))))



;; Without reduce, I just want to read one value off the flow, how?

;; So Flows are encoded as function, which are invoked by 2 callbacks.
(comment
(def d)
(def s (m/seed [1 2 3 4]))
(def it (s
(fn notify [] (println ::Notify))
(fn notify [] (println ::Cancel))))
@it
(it)

(def !a (atom []))
(def a (m/watch !a))
(def bit (a
(fn notify [] (println ::Notify))
(fn notify [] (println ::Cancel))))
@bit
(reset! !a [1])
@bit
(swap! !a conj 3)
(swap! !a conj 4)
(swap! !a conj 5)
(swap! !a conj 6)
@bit

(defrecord node-events [action-type node-data event-data])
(->node-events
:new-node
{:rect11 {:id :rect11
:x 50.99
:y 60.0
:type-specific-data {:text "GM Hello"
:width 400
:height 800}
:type "rect"
:fill "lightblue"}}
{:graph-name :main}))
;; Here's a breakdown of how this works:

;; The Seed.run method returns a Process object. This Process class is an inner class of Seed and has some important characteristics:

;; It implements AFn (making it callable as a function) and IDeref (making it derefable).
;; It holds the iterator for the collection, along with notifier and terminator functions.)
;;
;; (m/seed my-collection) returns a function that, when called with notifier and terminator functions,
;; creates and returns a Process object.
;; The Process object:
;;
;; Can be derefed (@process) to get the next item from the collection.
;; Can be called as a function ((process)) to cancel the iteration.
;;
;;
;; Each time you deref the Process:
;;
;; It returns the next item from the collection.
;; It calls the notifier function if there are more items.
;; It calls the terminator function when the iteration is complete.
;;
;;
;; If you call the Process as a function, it cancels the iteration, preventing further items from being retrieved.

(comment
(m/seed [1 2 3])
(m/ap)
(m/buffer)
(m/eduction)
(m/group-by)

(m/latest (m/seed [1 2 3])) ;; Running inf flows concurrently.
(m/mbx);; A hunch that this seems to fit somewhere not sure where
(m/memo) ;; for task Returns a new publisher.
(m/observe)
(m/publisher)
(m/rdv)
(m/reduction)
(m/relieve)
(m/sample)
(m/seed)
(m/signal)
(m/stream)
(m/subscribe)
(m/watch)
(m/zip))

27 changes: 27 additions & 0 deletions src/app/client/shapes/draw_rect.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(ns app.client.shapes.draw-rect
(:require contrib.str
[hyperfiddle.electric-svg :as svg]
[hyperfiddle.electric :as e]
[hyperfiddle.electric-dom2 :as dom]
[hyperfiddle.electric-ui4 :as ui]
[clojure.pprint :as pprint]
[app.client.style-components.svg-icons :refer [get-icon]]
[app.client.mode :refer [theme]]
#?@(:cljs [[clojure.string :as str]
[global-flow :refer [!global-atom current-time-ms]]])))


(e/defn draw-rect []
(e/client
(dom/button
(dom/props {:style {:display "flex"
:background-color "red"}})
(dom/text "GM")
(dom/on "click" (e/fn [e]
(e/client
(do
(println "BEF" @!global-atom)
(reset! !global-atom {:type :draw-rect
:action :start-drawing
:time (current-time-ms)})
(println "clicked seddings"@!global-atom))))))))
Loading
Loading