0.16.10 • Published 4 years ago

baahu v0.16.10

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

What is Baahu?

Baahu is a small zero-dependency Moore machine-based UI framework for Javascript + TypeScript

Features

Get Started

Everything you need to know about Baahu is in the docs!

Try it out live on Code Sandbox!

Example Components

You should read the docs, but if you want a sneak peek at what the API looks like, here a couple of example components:

Toggle

import { b, machine, emit } from 'baahu';

const Toggle = machine({
  id: 'toggle',
  initial: 'inactive',
  context: () => ({}),
  when: {
    inactive: { on: { TOGGLE: { to: 'active' } } },
    active: { on: { TOGGLE: { to: 'inactive' } } },
  },
  render: state => (
    <div>
      <h3>{state}</h3>
      <button onClick={() => emit({ type: 'TOGGLE' })}>Toggle</button>
    </div>
  ),
});

Traffic Light

A traffic light component that doesn't let you cross the street when it is red, and displays the # of times you crossed the street.

codesandbox

import { b, machine, emit } from 'baahu';

/** returns a function that is called by baahu. emit the
 * provided event after the specified time */
function delayedEmit(event, delayMS) {
  return () => setTimeout(() => emit(event, 'light'), delayMS);
}

/**
 * you can make your own abstractions like `delayedEmit`
 * for entry/exit/"do" actions.
 *
 * embracing js/ts (as opposed to shipping with every
 * possible abstraction) keeps baahu fast and light!
 */

const Light = machine({
  id: 'light',
  initial: 'red',
  context: () => ({
    streetsCrossed: 0,
  }),
  when: {
    red: {
      entry: delayedEmit({ type: 'START' }, 3000),
      on: {
        START: {
          to: 'green',
        },
        CROSS: {
          do: () => alert('JAYWALKING'),
        },
      },
    },
    yellow: {
      entry: delayedEmit({ type: 'STOP' }, 1500),
      on: {
        STOP: {
          to: 'red',
        },
        CROSS: {
          do: ctx => ctx.streetsCrossed++,
        },
      },
    },
    green: {
      entry: delayedEmit({ type: 'SLOW_DOWN' }, 2500),
      on: {
        SLOW_DOWN: {
          to: 'yellow',
        },
        CROSS: {
          do: ctx => ctx.streetsCrossed++,
        },
      },
    },
  },
  render: (state, ctx) => (
    <div>
      <h3>{state}</h3>
      {/* this is a targeted event: 
        only the machine with the specified
        id will be checked */}
      <button onClick={() => emit({ type: 'CROSS' }, 'light')}>
        Cross the Street
      </button>
      <p>Time(s) street crossed: {ctx.streetsCrossed}</p>
    </div>
  ),
});
0.16.10

4 years ago

0.16.8

4 years ago

0.16.7

4 years ago

0.16.6

4 years ago

0.16.4

4 years ago

0.16.3

4 years ago

0.16.2

4 years ago

0.16.1

4 years ago

0.16.0

4 years ago

0.15.2

4 years ago

0.15.1

4 years ago

0.15.0

4 years ago

0.14.14

4 years ago

0.14.12

4 years ago

0.14.11

4 years ago

0.14.10

4 years ago

0.14.5

4 years ago

0.14.6

4 years ago

0.14.7

4 years ago

0.14.8

4 years ago

0.14.9

4 years ago

0.14.4

4 years ago

0.14.3

4 years ago

0.14.0

4 years ago

0.14.1

4 years ago

0.14.2

4 years ago

0.12.4

4 years ago

0.12.5

4 years ago

0.12.1

4 years ago

0.12.2

4 years ago

0.12.3

4 years ago

0.12.0

4 years ago

0.11.17

4 years ago

0.11.16

4 years ago

0.11.15

4 years ago

0.11.14

4 years ago

0.11.12

4 years ago

0.11.11

4 years ago

0.11.10

4 years ago

0.11.9

4 years ago

0.11.8

4 years ago

0.11.7

4 years ago

0.11.6

4 years ago

0.11.5

4 years ago

0.11.4

4 years ago

0.11.3

4 years ago

0.11.2

4 years ago

0.11.1

4 years ago

0.11.0

4 years ago

0.10.10

4 years ago

0.10.9

4 years ago

0.10.8

4 years ago

0.10.7

4 years ago

0.10.6

4 years ago

0.10.5

4 years ago

0.10.3

4 years ago

0.10.4

4 years ago

0.10.1

4 years ago

0.10.2

4 years ago

0.10.0

4 years ago

0.9.7

4 years ago

0.9.6

4 years ago

0.9.5

4 years ago

0.9.4

4 years ago

0.9.3

4 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.9.0

4 years ago

0.7.11

4 years ago

0.7.10

4 years ago

0.7.9

4 years ago

0.7.12

4 years ago

0.7.15

4 years ago

0.7.14

4 years ago

0.8.0

4 years ago

0.7.8

4 years ago

0.7.6

4 years ago

0.7.5

4 years ago

0.7.7

4 years ago

0.7.4

4 years ago

0.7.2

4 years ago

0.7.3

4 years ago

0.7.1

4 years ago

0.6.9

4 years ago

0.6.10

4 years ago

0.7.0

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.2

4 years ago

0.3.3

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.1

4 years ago

0.1.2

4 years ago

0.2.0

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.2.3

4 years ago

0.1.4

4 years ago

0.2.2

4 years ago

0.1.3

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago