GithubHelp home page GithubHelp logo

isabella232 / okulary Goto Github PK

View Code? Open in Web Editor NEW

This project forked from funcool/okulary

0.0 0.0 0.0 38 KB

Fast Atom and DerivedAtom for ClojureScript.

License: Mozilla Public License 2.0

Shell 1.27% Clojure 96.68% HTML 2.05%

okulary's Introduction

okulary

A faster Atom and DerivedAtom impl for clojurescript.

{:deps {funcool/okulary {:mvn/version "2022.04.11-16"}}}

Atom

Is a Faster (mainly related to watcher handling) implementation of Atom reference type (of clojurescript).

(require '[okulary.core :as ol])

(def myatom (ol/atom 0))

@myatom
;; => 0

It behaves almost identically to the default builtin atom. Just dispatches the watchers much faster. being faster don't mean better than the default one. The implementation of this library has tradeoffs:

  • Only supports keys as strings or JavaScript Symbols. Using anything different is considered undefined behaviour.
  • Validators are not supported.
  • Does not implements IMeta protocol.

The main use case for this implementation is for situations where you have a huge amount of watchers and you want watcher dispatching very fast.

Derived Atom

The DerivedAtom is like a read-only cursor, and can derive from the atom defined in this library or any that implements the IWatchable protocol (clojurescript builtin Atom as example).

(def a1 (ol/atom {:a 1 :b 1}))
(def d1 (ol/derived :a a1))

@a1
;; => {:a 1 :b 1}

@d1
;; => 1

The relevant features of DerivedAtom's:

  • They don't need resource management. If no watcher is attached the selector function will not be executed and this will not add overhead.
  • If the source value is the same, selector will be omited and a cached value will be used.
  • Only attaches 1 watcher to the parent atom-like independently of the number of watchers this derived atom will have.
  • The watchers on derived atom will be called only if the value is changed using the identical? equality check (you can provide your own equality function as third argument to derived).
  • Selector will be called twice on each change of the parent atom-like reference when no local cache is found and once when a cache is available.

okulary's People

Contributors

niwinz 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.