All Projects β†’ StoneCypher β†’ Flocks.js

StoneCypher / Flocks.js

Licence: mit
A radically simpler alternative to Flux - opinionated React state and rendering management

Programming Languages

javascript
184084 projects - #8 most used programming language
js
455 projects

Projects that are alternatives of or similar to Flocks.js

plume2
πŸš€a lightweight React state container for web and app
Stars: ✭ 74 (+2.78%)
Mutual labels:  flux, simple
General Store
Simple, flexible store implementation for Flux. #hubspot-open-source
Stars: ✭ 171 (+137.5%)
Mutual labels:  data, flux
Simple Neural Networks
Simple neural networks based only on Numpy
Stars: ✭ 114 (+58.33%)
Mutual labels:  simple, layer
Android Nosql
Lightweight, simple structured NoSQL database for Android
Stars: ✭ 284 (+294.44%)
Mutual labels:  data, simple
Muze
Composable data visualisation library for web with a data-first approach now powered by WebAssembly
Stars: ✭ 1,153 (+1501.39%)
Mutual labels:  data
Facebook Archive
Just some fun you can have with facebook's archive data
Stars: ✭ 63 (-12.5%)
Mutual labels:  data
Korea Startups
🌟 κ΅­λ‚΄ μŠ€νƒ€νŠΈμ—… λͺ©λ‘ 및 μ„€λͺ… 🌟
Stars: ✭ 63 (-12.5%)
Mutual labels:  data
Legislator
Interface to the Comparative Legislators Database
Stars: ✭ 62 (-13.89%)
Mutual labels:  data
Proteus
Proteus : A JSON based LayoutInflater for Android
Stars: ✭ 1,179 (+1537.5%)
Mutual labels:  data
Cofx
A node and javascript library that helps developers describe side-effects as data in a declarative, flexible API.
Stars: ✭ 72 (+0%)
Mutual labels:  data
Observable
minimalist event system for Python
Stars: ✭ 66 (-8.33%)
Mutual labels:  simple
Python dataee
python data ; kηΊΏθœ‘ηƒ›ε›Ύ
Stars: ✭ 63 (-12.5%)
Mutual labels:  data
Codeigniter4 Auth
A simple authentication library for CodeIgniter 4.
Stars: ✭ 70 (-2.78%)
Mutual labels:  simple
Tfjs Data
Simple APIs to load and prepare data for use in machine learning models
Stars: ✭ 63 (-12.5%)
Mutual labels:  data
Covid19
JSON time-series of coronavirus cases (confirmed, deaths and recovered) per country - updated daily
Stars: ✭ 1,177 (+1534.72%)
Mutual labels:  data
Fredr
An R client for the Federal Reserve Economic Data (FRED) API
Stars: ✭ 61 (-15.28%)
Mutual labels:  data
Starter React Flux
Generate your React PWA project with TypeScript or JavaScript
Stars: ✭ 65 (-9.72%)
Mutual labels:  flux
Reactive Flux
Fluxish model implemented with RxJS
Stars: ✭ 71 (-1.39%)
Mutual labels:  flux
Etymap
Interactive visualization of Wiktionary words and etymologies.
Stars: ✭ 65 (-9.72%)
Mutual labels:  data
Colour
Colour Science for Python
Stars: ✭ 1,131 (+1470.83%)
Mutual labels:  data

flocks

A radically simpler alternative to Flux - opinionated React state and rendering management

Language   Platform   License   Status

NPM Downloads

What the hell is this?

So flux is pretty cool. But, I wanted something simpler, because I wanted to move faster. So, I created flocks - a flux alternative.

The primary goal of flocks.js is extreme simplicity.

There is a propaganda page developing at the website http://flocks.rocks/.

You can be up and running in five minutes. Try the Flocks quick start.

What's the big deal

The goal of the flux model is unidirectional state. That's admirable. It leads to large simplifications, and has a big positive impact on debugging.

However, it's also a very large amount of boilerplate, requires the implementation of a bunch of patterns to get anything done, and provides an eight point flowchart on how to update a value, which in practice is an under-sell of the complexity.

I wanted something simpler. I wanted something that felt like a global, that gave me transactionality, atomicity, and that didn't have me reimplementing things every time I started.

I wanted something where just calling a function got the job done.

So I created flocks.

Get on with it; show some code

This is a complete flocks app which shares data between three simple controls, all fully defined in this snippet. The only code not present in this example is the copies of react and flocks being pulled from CDN.

<!doctype html>
<html>

  <head>

    <meta charset="utf-8">
    <title>Example Spinner App</title>

    <style type="text/css">
      body   { font-size: 600%; font-family: helvetica neue, sans-serif; }
      button { font-size: 50%; margin: 2em; }
    </style>

    <script defer src="http://fb.me/JSXTransformer-0.12.2.js"></script>
    <script defer src="http://fb.me/react-0.12.2.js"></script>
    <script defer src="http://cdnjs.cloudflare.com/ajax/libs/flocks.js/0.15.1/flocks.js"></script>

    <script defer type="text/jsx">

      // up button control
      var Up = flocks.createClass({
        inc:    function() { this.fset('value', this.fctx['value'] + 1) },
        render: function() { return <button onClick={this.inc}>β–²</button>; }
      });

      // down button control
      var Down = flocks.createClass({
        dec:    function() { this.fset('value', this.fctx['value'] - 1) },
        render: function() { return <button onClick={this.dec}>β–Ό</button>; }
      });

      // the application root control
      var SpinnerApp = flocks.createClass({
        render: function() { return <div><Up/>{this.fctx['value']}<Down/></div>; }
      });

      // telling flocks where to put the app control, and what that control is
      var FlocksConfig = { target: document.body, control: SpinnerApp };
      var InitialState = { value: 0 };

      // and mount the app πŸ˜„
      flocks.mount(FlocksConfig, InitialState);

    </script>

  </head>

  <body></body>

</html>

Why is this different?

There's basically no boilerplate, and updating is easy.

There're no dispatchers; there're no actions; there're no stores.

It's all automatic. You don't need to manage anything, or worry about conflicts between actions.

Your applications become atomic, and transactional, very similar to state machines, very close to being purely declarative. You can validate states before they go into place.

The simplicity is unmatched.

var Config = {
      target  : document.body,
      control : YourControl
    },

    Data = {
      logged_in: true,
      user_name: "Bob Dobbs",
      icon: "http://upload.wikimedia.org/wikipedia/en/a/a3/Bobdobbs.png"
    },

    Update = Flocks.mount(Config, Data);

Done.

Want to change the state of the app?

Update.set("user_name", "JR \"Bob\" Dobbs");

Done.

If you want that from inside the control, or even inside the heirarchy, that's fine; props, state, and contexts will cascade down safely and normally.

Now, you just write your app as a single control, and keep state 100% outside of the control heirarchy. :)

How is this better?

It's:

  • Simpler
  • Centralized
  • Atomic
  • Transactional

Simpler

Learn two functions and one member of this, and you're off to the races.

Learn more tools as they become convenient.

Centralized

Your entire render state - maybe your entire state, if you like - in one simple place.

Read and write the whole thing at once, if convenient. This is surprisingly often convenient.

Atomic

Batch writes and locking let you prevent the rendering of intermediate states.

All the convenience of piecewise and group update with none of the flash of content.

Transactional

That's right, dust off your SQL brain, because you can write a function that invalidates and rejects application update sets.

Imagine what this will do for your debugging. 😹

Would you explain more clearly?

What Flocks actually does is to provide you with an update function.

To get started, tell Flocks where the mount point is and what control to use. Then, Flocks will create that control in place, and provide you an update function.

The idea is that you're supposed to let Flocks manage the part of your application's state that gets visibly rendered. (You can let it manage the whole state, if you want to; I often do. But you don't have to.)

Once that's done, the whole shebang is just taken off your shoulders. No update calls. No dispatching. No events. No broadcasting. No registration or deregistration.

Just simple prop-style updates. It's quite liberating.

Example plox

There is an example page developing at the Flocks propaganda site http://flocks.rocks/.

Endnotes

Are you using my lib? Please let me know. I'm curious!

If you want to reach me, try stonecypher at gmail dot com, please. Thanks :)

Polemic

flocks is MIT licensed, because viral licenses and newspeak language modification are evil. Free is only free when it's free for everyone.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].