Giter Club home page Giter Club logo

irinse's Introduction

Irinse

Introduction

irinse is a collection of simple reagent components.

Install

The simplest way to use irinse in a clojurescript project, is by including it in the dependency vector on your project.clj file:

Clojars Project

Events

Creating event streams

To listen to events from a reagent component, you'll need to create a subject. The subject acts like a function so you can call it's next method.

(require '[beicon.core :as rx]
         '[irinse.beiconx :as rxt]) ;; import beiconx as subjects can be used as functions

(let [v (rx/subject)
      _ (rxt/log "Value" v)]
    (v 1) ;; ==> Value: 1
    (v [1 2]) ;; ==> Value: [1 2]
    (v)) ;; end

Converting streams to state

We could use reagent atoms to store the values from streams mainly because reagent itself does not work with reactive streams.

(def name-stream (rx/subject))

(def name (rxt/to-ratom "" name-stream))

@name 
;; ==> ""

(name-stream "noxecane")
(name-stream "Obasanjo")
 
@name
;; ==> "Obasanjo"

One could also reduce over the state

(def fill-list (rx/subject))
(def ilist (rxt/to-ratom [] conj fill-list))

(fill-list 12)
(fill-list 13)
(fill-list 14)

@ilist
;; ==> [12 13 14]

Converting a channel to an observable

There is an equivalent function to from-promise for core.async channels. Bear in mind that buffers don't matter as this function eagerly consume new events from the channel and dispatches them regardless of availability of subscribers. Hence, more like subjects, only events received after subscription matter.

(require '[cljs.core.async :as a])

(def b (a/chan 1))

(def c (rxt/from-chan a))
(rxt/log "From Channel" c)

(a/put! b 10)
;; ==> From Channel: 10

Creating Simple forms

For instance to create a login form component

(require '[irinse.forms :as form])

(defn model [{:keys [login-service]}]
  (let [write  (rx/subject)
        submit (rx/subject)
        state  (form/writes write) ;; reduce write events over a map [:name :value]
        login  (rx/flat-map  submit)] ;
    {:write  write
     :submit submit
     :state  state}))

(defn view [{:keys [write submit state]}]
  (fn []
    [:form
      [:input.input {:type      "text"
                     :on-change (form/input write [:username])}]
      [:input.input {:type      "password"
                     :on-change (form/input write [:password])}]
      [:button.button {:type     "button"
                       :on-click #(submit @state)}]]))

License

irinse is licensed under GPLv3 license:

irinse's People

Contributors

noxecane avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

irinse's Issues

select with large number of options

Sometimes users need to select an element but the possible number of options is to large for the select list to be user friendly. I would suggest using an autocomplete field

convert stream to reagent atom

reagent does not work with observable streams. It has a customized version of atoms as a replacement of observable streams. So for streams to write to reagent views such atoms have to act as proxy

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.