All Projects → felangel → Hydrated_bloc

felangel / Hydrated_bloc

Licence: mit
An extension to the bloc state management library which automatically persists and restores bloc states.

Programming Languages

dart
5743 projects
dartlang
94 projects

Projects that are alternatives of or similar to Hydrated bloc

React Composition Api
🎨 Simple React state management. Made with @vue/reactivity and ❤️.
Stars: ✭ 67 (-62.98%)
Mutual labels:  state-management, state
Vue State Store
📮 VSS (Vue State Store) - Vue State Management (with Publish & Subscribe pattern)
Stars: ✭ 128 (-29.28%)
Mutual labels:  state-management, state
Radon
Object oriented state management solution for front-end development.
Stars: ✭ 80 (-55.8%)
Mutual labels:  state-management, state
Duix
A State Manager focused on KISS and Pareto's Principle
Stars: ✭ 48 (-73.48%)
Mutual labels:  state-management, state
Freactal
Clean and robust state management for React and React-like libs.
Stars: ✭ 1,676 (+825.97%)
Mutual labels:  state-management, state
Alveron
Elm & Reason inspired state management for React
Stars: ✭ 57 (-68.51%)
Mutual labels:  state-management, state
React Workshop
⚒ 🚧 This is a workshop for learning how to build React Applications
Stars: ✭ 114 (-37.02%)
Mutual labels:  state-management, state
Revived
A redux-inspired predictable state container for python
Stars: ✭ 12 (-93.37%)
Mutual labels:  state-management, state
Pure Store
A tiny immutable store with type safety.
Stars: ✭ 133 (-26.52%)
Mutual labels:  state-management, state
Swiftdux
Predictable state management for SwiftUI applications.
Stars: ✭ 130 (-28.18%)
Mutual labels:  state-management, state
Python Diskcache
Python disk-backed cache (Django-compatible). Faster than Redis and Memcached. Pure-Python.
Stars: ✭ 992 (+448.07%)
Mutual labels:  cache, persistence
Redux Rs
📦 A Rust implementation of Redux.
Stars: ✭ 158 (-12.71%)
Mutual labels:  state-management, state
Use Global Context
A new way to use “useContext” better
Stars: ✭ 34 (-81.22%)
Mutual labels:  state-management, state
Yewdux
Redux-like state containers for Yew apps
Stars: ✭ 58 (-67.96%)
Mutual labels:  state-management, state
Concent
State management that tailored for react, it is simple, predictable, progressive and efficient.
Stars: ✭ 882 (+387.29%)
Mutual labels:  state-management, state
Reworm
🍫 the simplest way to manage state
Stars: ✭ 1,467 (+710.5%)
Mutual labels:  state-management, state
Pullstate
Simple state stores using immer and React hooks - re-use parts of your state by pulling it anywhere you like!
Stars: ✭ 683 (+277.35%)
Mutual labels:  state-management, state
Redux Tree
An alternative way to compose Redux reducers
Stars: ✭ 23 (-87.29%)
Mutual labels:  state-management, state
Stateshot
💾 Non-aggressive history state management with structure sharing.
Stars: ✭ 128 (-29.28%)
Mutual labels:  state-management, state
Contextism
😍 Use React Context better.
Stars: ✭ 141 (-22.1%)
Mutual labels:  state-management, state

⚠️ Attention: This repository has been moved to https://github.com/felangel/bloc and is now read-only!

Hydrated Bloc

Pub Version Build Status Code Coverage style: effective dart MIT License Starware Bloc Library

An extension to the bloc state management library which automatically persists and restores bloc states and is built on top of hydrated_cubit.

Overview

hydrated_bloc exports a Storage interface which means it can work with any storage provider. Out of the box, it comes with its own implementation: HydratedStorage.

HydratedStorage is built on top of path_provider for a platform-agnostic storage layer. The out-of-the-box storage implementation reads/writes to file using the toJson/fromJson methods on HydratedBloc and should perform very well for most use-cases (performance reports coming soon). HydratedStorage is supported for desktop (example).

Usage

1. Use HydratedStorage

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  HydratedBloc.storage = await HydratedStorage.build();
  runApp(App());
}

2. Extend HydratedBloc and override fromJson/toJson

enum CounterEvent { increment, decrement }

class CounterBloc extends HydratedBloc<CounterEvent, int> {
  CounterBloc() : super(0);

  @override
  Stream<int> mapEventToState(CounterEvent event) async* {
    switch (event) {
      case CounterEvent.decrement:
        yield state - 1;
        break;
      case CounterEvent.increment:
        yield state + 1;
        break;
    }
  }

  @override
  int fromJson(Map<String, dynamic> json) => json['value'] as int;

  @override
  Map<String, int> toJson(int state) => { 'value': state };
}

Now our CounterBloc is a HydratedBloc and will automatically persist its state. We can increment the counter value, hot restart, kill the app, etc... and our CounterBloc will always retain its state.

Custom Storage Directory

By default, all data is written to temporary storage which means it can be wiped by the operating system at any point in time.

An optional storageDirectory can be provided to override the default temporary storage directory:

HydratedBloc.storage = await HydratedStorage.build(
  storageDirectory: await getApplicationDocumentsDirectory(),
);

Custom Hydrated Storage

If the default HydratedStorage doesn't meet your needs, you can always implement a custom Storage by simply implementing the Storage interface and initializing HydratedBloc with the custom Storage.

// my_hydrated_storage.dart

class MyHydratedStorage implements Storage {
  @override
  dynamic read(String key) {
    // TODO: implement read
  }

  @override
  Future<void> write(String key, dynamic value) async {
    // TODO: implement write
  }

  @override
  Future<void> delete(String key) async {
    // TODO: implement delete
  }

  @override
  Future<void> clear() async {
    // TODO: implement clear
  }
}
// main.dart

HydratedBloc.storage = MyHydratedStorage();

Maintainers

Supporters

Starware

Hydrated Bloc is Starware.
This means you're free to use the project, as long as you star its GitHub repository.
Your appreciation makes us grow and glow up. ⭐

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].