Giter VIP home page Giter VIP logo

minicitrus's Introduction

minicitrus.alpha

Simplified state management library for ClojureScript inspired by Citrus

DEPS

If you're copying this the second time leave a star

tools.deps

mdrobulis/minicitrus {git/url "https://github.com/mdrobulis/minicitrus" :sha <look it up> }

Motivation and GOALS

Inspired by citrus and re-frame event dispach function. Demotivated by too many concepts

So I made this thing.

Goals

  • remove event handler code from inside your componet
  • remove the inline handler functions "#(..." or "(fn [e] ..."
  • access to a global atom for state changes
  • Easy to learn.
  • Close to bare metal
  • Hide core.async

Usage

You have 2 entry points

(publish ::your-event-key data)  ;; for use inside components for event handlers.
`
``` clojure
(defmethod handler ::your-event-key [_ data]
   #_do_stuff
 )

Default handler logs all the details of the event into console

publish and handler are variadic

First argument of handler is a map that includes

  • :argument of the event
  • :key event routing key
  • :state global state atom defined in minicitrus ns. feel free to use it or not.

inside your code

(your.ns
   (:require [minicitrus.alpha :as mc])
)

(defmethod mc/handler ::add-product  [global product]
    (let [state (global :state)]
       (swap! state conj product)       
     )
)

(rum/defc product-list [product-list]
  [:div
    (let [product product-list]
     [:div
       [:label (:name item)]
       [:button
          {:on-click (mc/publish ::add-product product ) }
          "Add"]
       [:button
          {:on-click (mc/publsh  ::remover-product product )}
          "Remove"]
       ])]
       )

Under the hood

  • single core.async chanel for event aggregation
  • Event loop that routes the events to the handler multimethod

Contributions and feedback

pull requests are welcome for

  • cljc implementation for use in Java UI
  • better ways to inject different kinds of state. // Reagent atoms, datascript
  • Tests

License

Copyright © 2020 Martynas Drobulis

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

minicitrus's People

Watchers

Martynas Drobulis avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.