membrane

Ben Sless 2021-10-27T19:28:16.005600Z

How should asynchrony be handled in membrane? can I emit effects asynchronously? If things run in futures, how do I get the data back? another effect? maybe completable future and emit the effect on complete?

phronmophobic 2021-10-27T19:37:06.009500Z

Membrane purposefully doesn't include much for effects since how effects should be handled should be use-case driven. Membrane is meant to work with whatever effects system makes sense for your use case. For any event handler, it only makes sense to return intents synchronously, but they can be handled synchronously or asynchronously as needed. Within a defeffect, you can use futures along with dispatch!.

(defeffect ::increment-number [$num]
  (future
    (dispatch! :update $num inc)
    (prn (dispatch! :get $num))))

phronmophobic 2021-10-27T19:37:59.010400Z

If you're using the builtin membrane.component stuff, then the :update and :set effects will update app state

phronmophobic 2021-10-27T19:40:06.011700Z

When you create your view-fn with membrane.component/make-app, you can pass in the atom to use for the app state. So another option is just to use an add-watch on the atom.

phronmophobic 2021-10-27T19:42:38.013700Z

The docs could be improved on this topic, but it was a design goal that membrane doesn't dictate these sorts of decisions like how asynchrony should work. If you have a few more details about your use case, I can provide a more helpful response for what that might look like with membrane.

phronmophobic 2021-10-27T19:56:22.015100Z

I think it's an anti pattern when you have React db, and a React debugger, and a React effects system. All this stuff should be composable

Ben Sless 2021-10-27T19:56:58.015500Z

Thank you, Going back to the HN reader example:

(defn load-kids
  [kids]
  (when kids
    (into
     []
     (comp
      (map deref)
      (map (fn [{:keys [kids] :as kid}]
             (if kids
               (assoc kid :kids (load-kids kids))
               kid))))
     (mapv fetch-id! kids))))

(defeffect ::load-comments [$comments kids]
  (dispatch! :update $comments (fn [_] (load-kids kids))))
looks like I can arbitrarily dispatch effects in futures

Ben Sless 2021-10-27T19:57:00.015800Z

which is excellent

Ben Sless 2021-10-27T19:57:08.016Z

the UI will update dynamically

phronmophobic 2021-10-27T20:00:12.017500Z

there are 2 caveats: • if you don't use a futures, you can still tie up the main thread • if you do use futures, you may need to call repaint. I've been meaning to add a builtin :repaint effect, but haven't gotten around to it yet.

Ben Sless 2021-10-28T10:29:31.019400Z

I think I'll try with CF so I can register callbacks

phronmophobic 2021-10-27T20:05:37.019100Z

I still haven't forgotten about the RichTextView. I made some improvements to how fonts are looked up and loaded that were required, but still need to package that into something that makes it easy to use.

2021-11-24T15:06:49.033700Z

RichTextView ... rich

🤣 1