npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

alumina

v0.1.14

Published

small virtual dom framework

Downloads

5

Readme

Alumina

Alumina is a react-like small UI framework. It aims to rapid and easy development for small applications. In order to make the state management easier, it adopts the scheme whole virtual dom tree reconciled after each user interaction. Due to that approach, you can write the store or model without complex state management libraries.

Usage

Install

  npm install alumina

Configurations

There are configuration example projects for typescript and well-used bundlers in alumina-setup-examples repo. Please check them for the reference.

Basic Examples

Hello world

import { render, jsx } from 'alumina';

const App = () => (
  <div>
    hello world
  </div>
);
render(() => <App />), document.getElementById('app'));

Counter

import { render, jsx } from 'alumina';

let count = 0;
const Counter = () => (
  <div onClick={() => count++}>
    {count}
  </div>
)
render(() => <Counter />, document.getElementById('app'));

Counter (with class model)

import { render, jsx } from 'alumina';

class CounterModel {
  count: number = 0;
  increment = () => {
    this.count++;
  };
}
const counterModel = new CounterModel();

const Counter = () => {
  const { count, increment } = counterModel;
  return <div onClick={increment}>{count}</div>;
};

render(() => <Counter />, document.getElementById('app'));

Counter (with vuex like state management)

import { render, jsx } from 'alumina';

function createStore() {
  const state = {
    count: 0,
  };
  const getters = {
    get countDouble() {
      return state.count * 2;
    },
  };
  const actions = {
    increment() {
      state.count++;
    },
    reset() {
      state.count = 0;
    },
  };
  return { state, getters, actions };
}

const store = createStore();

const Counter = () => {
  const {
    state: { count },
    getters: { countDouble },
    actions: { increment, reset },
  } = store;
  return (
    <div>
      <div>count: {count}</div>
      <div>x2: {countDouble}</div>
      <div>
        <button onClick={increment}>add</button>
        <button onClick={reset}>reset</button>
      </div>
    </div>
  );
};

render(() => <Counter />, document.getElementById('app'));

The state management part doesn't depend on how the view updated. You can design your store with free ideas!

Usage Notes

Async Update

Alumina automatically updates the view after every DOM callback functions (such like onClick, onMouseMove, ...etc). However for other cases, especially for async function call, rerender() function should be invoked explicitly to update the view.

import { jsx, rerender } from 'alumina';

const store = {
  message: 'hello',
};

const changeMessageAsync = () => {
  setTimeout(() => {
    store.message = 'world';
    rerender(); // manually trigger rendering
  }, 1000);
};
const App = () => {
  return (
    <div onClick={changeMessageAsync}>
      <p>{store.message}</p>
    </div>
  );
};

If prop

const App = () => (
  <div>
    <div>shown</div>
    <div if={true}>shown</div>
    <div if={false}>hidden</div>
    <SomeComponent if={false} />
  </div>
);

There is if prop. When falsy value passed, the element is not rendered. It also applicable to function components.

Class props propagation

  const Foo = () => <div class="foo" />;
  const App = () => <Foo class="bar" />;
  // --> renders the DOM <div class="foo bar"></div>

Function component accepts class prop and it is added to the class attribute of the root element of returned dom tree. Useful for decorating child components in parent context.

Background

Alumina is originally developed for the insourcing UI framework for Kermite.

License

MIT license.