@wiredcraft/miniprogram-sparrow

Experimental Recoil inspired state management

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@wiredcraft/miniprogram-sparrow
130.1.0a year ago2 years agoMinified + gzip package size for @wiredcraft/miniprogram-sparrow in KB

Readme

Install

yarn add @wiredcraft/miniprogram-sparrow

Usage

// store/name.js

import { atom } from "sparrow";

export const firstName = atom("Jack");

// the action
export function updateFirstName(name) {
  write(firstName, name);
}

// components/hello.js
import { write, behavior as sparrow } from "sparrow";
import { firstName, updateFirstName } from "./store/name";

Component({
  atoms: { firstName },

  behaviors: [sparrow],
  lifetimes: {
    attached() {
      console.log(this.firstName);
    },
  },
  methods: {
    handleButtonOnTap() {
      updateFirstName("Rose");
    },
  },
});