Giter VIP home page Giter VIP logo

vxstate's Introduction

VxState

VxState is a state management library built for Flutter apps with focus on simplicity. It is inspired by StoreKeeper & libraries like Redux, Vuex etc with the power of streams. Here is a basic idea of how it works:

  • Single Store (Single source of truth) to keep app's data
  • Structured modifications to store with Mutations
  • Widgets listen to mutations to rebuild themselves
  • Enhance this process with Interceptors and Effects

Core of VxState is based on the InheritedModel widget from Flutter.

Getting started

Add to your pubpsec:

dependencies:
  ...
  vxstate: any

Create a store:

import 'package:vxstate/vxstate.dart';

class MyStore extends VxStore {
  int count = 0;
}

Define mutations:

class Increment extends VxMutation<MyStore> {
  perform() => store.count++;
}

Listen to mutations:

@override
Widget build(BuildContext context) {
  // Define when this widget should re render
  VxState.watch(context, on: [Increment]);

  // Get access to the store
  MyStore store = VxState.store as MyStore;

  return Text("${store.count}");
}

Complete example:

import 'package:flutter/material.dart';
import 'package:vxstate/vxstate.dart';

// Build store and make it part of app
void main() {
  runApp(VxState(
    store: MyStore(),
    child: MyApp(),
  ));
}

// Store definition
class MyStore extends VxStore {
  int count = 0;
}

// Mutations
class Increment extends VxMutation<MyStore> {
  perform() => store.count++;
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // Define when this widget should re render
    VxState.watch(context, on: [Increment]);

    // Get access to the store
    MyStore store = VxState.store as MyStore;

    return MaterialApp(
      home: Scaffold(
        body: Column(
          children: <Widget>[
            Text("Count: ${store.count}"),
            RaisedButton(
              child: Text("Increment"),
              onPressed: () {
                // Invoke mutation
                Increment();
              },
            ),
          ],
        ),
      ),
    );
  }
}

Documentation

  • VxStore - Where your apps's data is kept
  • VxMutation - Logic that modifies Store
  • VxBuilder, VxNotifier, VxConsumer - Useful widgets for special cases
  • VxEffect - Chained mutations
  • VxInterceptors - Intercept execution of mutations

vxstate's People

Contributors

iampawan avatar imgbotapp avatar

Stargazers

Liao Kun Yong avatar Fatih Mehmet Gurbuz avatar Phil avatar Akash25 avatar Eren avatar Thomas Cherickal avatar  avatar Prit Thakkar avatar Matt Czapliński avatar Waqas Mahmood Khan avatar David Feinberg avatar Kobi avatar Pratik Lama avatar Naresh Mahajan  avatar Daniel Victor Musinguzi (Donnie) avatar Lucas Silva avatar dev avatar Robert Nubla avatar Nikhil Patil avatar Plorence avatar Shohidul Islam avatar Mohammad Ali Khosravi avatar Mohammed Saif avatar Lukas Himsel avatar Anmol avatar Igor Zubkov avatar ELTAYEB ALI aka Fadie avatar Jayuchou avatar Jigyasu Tanwar avatar Payam Zahedi avatar  avatar Michael Black Ritter avatar  avatar Nehal Jaisalmeria avatar Akash Dubey avatar Tanmay Mohapatra avatar Mital Rakholiya avatar Iresh Sharma avatar  avatar junior oliveira avatar Kaustav Roy avatar Enikuomehin Adejuwon avatar

Watchers

James Cloos avatar  avatar  avatar  avatar

vxstate's Issues

listen method not define error

velocity-x version
velocity_x: ^2.1.0

VxState.listen(context, to: [AddMutation]);
yaha ye error message aa raha he:
The method 'listen' isn't defined for the type 'VxState'.
Try correcting the name to the name of an existing method, or defining a method named 'listen'.

Is that possible divide my store?

In my use case, I plan to have UserState, PostsState, CreatePostState and etc...

Due to using a single state tree, all states of our application are contained inside one big object. However, as our application grows in scale, the store can get really bloated.

Is that a good practice of example that can divide my store?

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.