{"id":13493765,"url":"https://github.com/Andy-set-studio/beedle","last_synced_at":"2025-03-28T12:32:25.193Z","repository":{"id":32811156,"uuid":"143339508","full_name":"Andy-set-studio/beedle","owner":"Andy-set-studio","description":"A tiny library inspired by Redux \u0026 Vuex to help you manage state in your JavaScript apps","archived":false,"fork":false,"pushed_at":"2022-12-08T17:16:05.000Z","size":2568,"stargazers_count":386,"open_issues_count":52,"forks_count":37,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-04T09:06:45.477Z","etag":null,"topics":["lightweight","minimal","reactive","state-machine","state-management","vanilla-javascript"],"latest_commit_sha":null,"homepage":"https://beedle.hankchizljaw.io","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Andy-set-studio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.MD","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-02T20:00:11.000Z","updated_at":"2024-07-26T13:23:57.000Z","dependencies_parsed_at":"2023-01-14T22:30:49.914Z","dependency_job_id":null,"html_url":"https://github.com/Andy-set-studio/beedle","commit_stats":null,"previous_names":["andybelldesign/beedle","hankchizljaw/beedle"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andy-set-studio%2Fbeedle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andy-set-studio%2Fbeedle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andy-set-studio%2Fbeedle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andy-set-studio%2Fbeedle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Andy-set-studio","download_url":"https://codeload.github.com/Andy-set-studio/beedle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246030699,"owners_count":20712422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lightweight","minimal","reactive","state-machine","state-management","vanilla-javascript"],"created_at":"2024-07-31T19:01:18.626Z","updated_at":"2025-03-28T12:32:20.184Z","avatar_url":"https://github.com/Andy-set-studio.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Beedle\n\n![The current build status based on whether tests are passing](https://api.travis-ci.org/andybelldesign/beedle.svg?branch=master)\n![The Uncompressed size of Beedle](http://img.badgesize.io/https://unpkg.com/beedle?label=Uncompressed%20Size)\n![The GZIP size of Beedle](http://img.badgesize.io/https://unpkg.com/beedle?compression=gzip\u0026label=GZIP%20Size)\n![The Brotli size of Beedle](http://img.badgesize.io/https://unpkg.com/beedle?compression=brotli\u0026label=Brotli%20Size)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nBeedle is a tiny library to help you manage state across your application. Inspired by great libraries like Vuex and Redux, Beedle creates a central store that enables you predictably control and cascade state across your application.\n\nThis library was initially created as a prototype for [this article on CSS-Tricks](https://css-tricks.com/build-a-state-management-system-with-vanilla-javascript/), where you learn how to build a state management system from scratch with Vanilla JavaScript.\n\n[**See the documentation**](https://beedle.hankchizljaw.io) — [**See the project structure**](https://beedle-structure.hankchizljaw.io)\n\n## Demos\n- [**Basic demo**](https://beedle-basic-demo.hankchizljaw.io/) \n- [**Advanced demo**](https://beedle-advanced-demo.hankchizljaw.io/) \n- [**Vue JS demo**](https://beedle-vue-demo.hankchizljaw.io/) \n- [**React JS demo**](https://beedle-react-demo.hankchizljaw.io/) \n\n# How it works\n\nBeedle creates a pattern where a single source of truth, the '*Application State*' cascades state across your app in a predictable fashion. To modify state, a set flow of `actions` and `mutations` help create a traceable data-flow that makes things a little easier to debug. \n\nUsing a [Pub/Sub pattern](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern) which notifies anything that is subscribed to changes, a fully reactive front-end can be achieved with a few kilobytes of vanilla JavaScript.\n\n![A flow diagram that shows an action that calls a mutation, which mutates the state and triggers an update to anything that is listening](https://s3-us-west-2.amazonaws.com/s.cdpn.io/174183/beedle-flow-diagram.png)\n\nAs the diagram above shows, a simple, predictable flow is created by pushing data into an `action` which subsequently calls one or more `mutations`. Only the `mutation` can modify state, which helps with keeping track of changes.\n\n[**Continue reading the documentation**](https://beedle.hankchizljaw.io/guide/state.html)\n\n## A mini library for small projects\n\nBeedle is inspired by libraries like Redux, but certainly isn't designed to replace it. Beedle is aimed more at tiny little applications or where a development team might be looking to create the smallest possible footprint with their JavaScript.\n\n## Performance budget\n\nBeedle is intended to be _tiny_, so the largest that the uncompressed size will ever get to is 5kb. \n\n## Browser support\n\nBeedle is aimed at browsers that support ES6 by default. It also uses a [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) to monitor state, so [anything that supports Proxy](https://caniuse.com/#feat=proxy) will support Beedle.\n\nYou could use the [Proxy polyfill](https://github.com/GoogleChrome/proxy-polyfill) to support more browsers.\n\nMost major browsers will support Beedle with no issues. \n\n## Getting started\n\nYou can pull Beedle down via [npm](http://npmjs.com) or take a [zip of this repository](https://github.com/hankchizljaw/beedle/archive/master.zip). The rest of this guide assumes you've used npm.\n\n### 1) Install\n\nRun `npm install beedle` in your project directory.\n\n\n\n### 2) Create a `store` instance\n\nFirst up, import it into your JavaScript:\n\n```JavaScript\nimport Store from 'beedle';\n```\n\n\n\nOnce you've got that you should create some `actions`, `mutations` and some initial state:\n\n```javascript\nconst actions = {\n    saySomething(context, payload) {\n        context.commit('setMessage', payload);\n    }\n};\n\nconst mutations = {\n    setMessage(state, payload) {\n        state.message = payload;\n\n        return state;\n    }\n};\n\nconst initialState = {\n    message: 'Hello, world'\n};\n```\n\nOnce you've got those setup, you can create a `Store` instance like this:\n\n```javascript\nconst storeInstance = new Store({\n    actions,\n    mutations,\n    initialState\n});\n```\n\n### 3) Use in your app\n\nLet's say you've got a text box that you type a message into. When the content is changed, it could dispatch a new message to your store:\n\n```javascript\n\n// Grab the textarea and dispatch the action on 'input'\nconst textElement = document.querySelector('textarea');\n\ntextElement.addEventListener('input', () =\u003e {\n\n    // Dispatch the action, which will subsequently pass this message to the mutation\n    // which in turn, updates the store's state\n    storeInstance.dispatch('saySomething', textElement.value.trim());\n});\n```\n\n### 4) Listen for changes\n\nBeedle uses the Pub/Sub pattern to transmit changes. Let's attach the message to a DOM element:\n\n```javascript\n// Grab the text element and attach it to the stateChange event\nconst messageElement = document.querySelector('.js-message-element');\n\n// This fires every time the state updates\nstoreInstance.subscribe(state =\u003e {\n    messageElement.innerText = state.message;\n});\n```\n\nHead over to the [basic demo](https://beedle-basic-demo.hankchizljaw.io/) to see this in action 🚀\n\n## Acknowledgements \n\nThanks to [Eli Fitch](https://twitter.com/EliFitch/) for giving me the idea to call this Beedle. This matches my preference to call my little projects names based on Zelda. [Here's Beedle from Zelda](https://zelda.gamepedia.com/Beedle).\n\nThanks to the incredible people who maintain projects such as [Redux](http://redux.js.org), [Vuex](http://vuex.vuejs.org) and [MobX](http://mobx.js.org) et. al. Thanks for making our lives easier and for inspiring this project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAndy-set-studio%2Fbeedle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAndy-set-studio%2Fbeedle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAndy-set-studio%2Fbeedle/lists"}