Giter Club home page Giter Club logo

basicstate's Introduction

# BasicState CI Status Latest Release

BasicState is a really, really simple key-value based state management solution. It makes use of BindableEvents to allow your projects to watch for changes in state, and provides a simple API for communication with your state objects. Think Rodux, but much more simple.

Getting Started

Visit the documentation site to get started with BasicState, see examples, and view the full documentation.

Contributors

A huge thanks to the contributors of this project. You've added some awesome new features and helps work out a few kinks.

Documentation

Documentation is available on the documentation site.

Examples

For examples, please see the documentation site.

Basic example:

local BasicState = require(path.to.BasicState)

local State = BasicState.new({
    Hello = "World"
})

State:GetChangedSignal("Hello"):Connect(function(NewValue, OldValue)
    print(string.format("Hello, %s; goodbye %s!", NewValue, OldValue))
end)

State:SetState({
    Hello = "Roblox"
})

--[[
    Triggers the RBXScriptConnection above and prints
    "Hello, Roblox; goodbye World!"
--]]

Usage with Roact

MyProject.Store.lua:

local BasicState = require(path.to.BasicState)

local Store = BasicState.new({
    Hello = "World"
})

return Store

MyProject.Components.MyComponent.lua:

local Roact = require(path.to.Roact)
local MyComponent = Roact.Component:extend("MyComponent")

local Store = require(script.Parent.Parent.Store)

function MyComponent:render()
    return Roact.createElement("TextButton", {
        Text = string.format("Hello, %s!", self.state.Hello),
        --> Displays "Hello, World!"

        [Roact.Event.MouseButton1Click] = function()
            Store:SetState({ Hello = "Roblox" })
            --> Will re-render and display "Hello, Roblox!"
        end
    })
end

--[[
    Wrap the component with the BasicState store and inject
    the value of Hello into the component state.
--]]
return Store:Roact(MyComponent, { "Hello" })

Get in Touch

Please refer to the thread on the Roblox Developer Forums if you wish to discuss BasicState. You can also contact me via direct message on the DevForums.

basicstate's People

Contributors

boatbomber avatar cxmeel avatar gaffal avatar rimuy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.