All Projects → blue-chip-js → Blue Chip

blue-chip-js / Blue Chip

Licence: mit
Normalizes GraphQL and JSON:API payloads into your state management system and provides ORM selectors to prepare data to be consumed by components

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Blue Chip

Mobx.dart
MobX for the Dart language. Hassle-free, reactive state-management for your Dart and Flutter apps.
Stars: ✭ 2,038 (+513.86%)
Mutual labels:  state-management, mobx
mst-effect
💫 Designed to be used with MobX-State-Tree to create asynchronous actions using RxJS.
Stars: ✭ 19 (-94.28%)
Mutual labels:  state-management, mobx
Mobx Rest
REST conventions for Mobx
Stars: ✭ 164 (-50.6%)
Mutual labels:  state-management, mobx
React Coat
Structured React + Redux with Typescript and support for isomorphic rendering beautifully(SSR)
Stars: ✭ 290 (-12.65%)
Mutual labels:  state-management, mobx
hooksy
Simple app state management based on react hooks
Stars: ✭ 58 (-82.53%)
Mutual labels:  state-management, mobx
React Atom
A simple way manage state in React, inspired by Clojure(Script) and reagent.cljs
Stars: ✭ 133 (-59.94%)
Mutual labels:  state-management, mobx
Pulse
✨ Pulse is a global state and logic framework for reactive Typescript & Javascript applications. Supporting frameworks like VueJS, React and React Native.
Stars: ✭ 243 (-26.81%)
Mutual labels:  state-management, mobx
Compare React State Management
React createContext vs Apollo vs MobX vs Redux in a simple todo app.
Stars: ✭ 81 (-75.6%)
Mutual labels:  state-management, mobx
mutable
State containers with dirty checking and more
Stars: ✭ 32 (-90.36%)
Mutual labels:  state-management, mobx
NObservable
MobX like observable state management library with Blazor support
Stars: ✭ 66 (-80.12%)
Mutual labels:  state-management, mobx
Prodo
Prodo is a React framework to build apps faster.
Stars: ✭ 114 (-65.66%)
Mutual labels:  state-management, mobx
Mobx Keystone
A MobX powered state management solution based on data trees with first class support for Typescript, support for snapshots, patches and much more
Stars: ✭ 284 (-14.46%)
Mutual labels:  state-management, mobx
Datx
DatX is an opinionated JS/TS data store. It features support for simple property definition, references to other models and first-class TypeScript support.
Stars: ✭ 111 (-66.57%)
Mutual labels:  state-management, mobx
Xsm
State Management made eXtraordinarily simple and effective for Angular, React, and Vue
Stars: ✭ 138 (-58.43%)
Mutual labels:  state-management, mobx
Reactstatemuseum
A whirlwind tour of React state management systems by example
Stars: ✭ 1,294 (+289.76%)
Mutual labels:  state-management, mobx
Flutter book
Flutter1.17.x book App,使用Mobx数据管理器支持Android和iOS,使用库json_serializable、json_annotation、dio。
Stars: ✭ 190 (-42.77%)
Mutual labels:  state-management, mobx
Mobx State Tree
Full-featured reactive state management without the boilerplate
Stars: ✭ 6,317 (+1802.71%)
Mutual labels:  state-management, mobx
Flutter Boilerplate Project
A boilerplate project created in flutter using MobX and Provider.
Stars: ✭ 1,194 (+259.64%)
Mutual labels:  state-management, mobx
ngx-mobx
Mobx decorators for Angular Applications
Stars: ✭ 14 (-95.78%)
Mutual labels:  state-management, mobx
react-coat-ssr-demo
Demo with Typescript + React + Redux for server-side-rendering (SSR)
Stars: ✭ 100 (-69.88%)
Mutual labels:  state-management, mobx

BlueChip · GitHub license npm version Docs API Build Status Coverage Status Created_By FullStack_Labs

BlueChip accepts payloads from GraphQL or JsonAPI servers, normalizes them into your store and provides an ORM like syntax for retrieving the data for use.

Table of Contents

The Basics

There are only two things that BlueChip does.

  1. Normalize data and organize it in a store.
  2. Retrieve the data from the store and prepare it for use.

What BlueChip Is

State API

BlueChip will take your data, normalize it and place it into a shared resources store. The API on this side is pretty minimal.

  • updateResources() Takes an entire payload of resources, normalize it and merge it into the store.
  • updateResource() Merges in a single resource into your store
  • removeResources() Removes a list of resource from the store
  • removeResource() Removes a single resource from the store
  • clearResources() Clears a resource store by types

And that is it for the State API.

Selector API

This is the meat of BlueChip. The selector API is how you prepare your data to be consumed by components. To select data, BlueChip offers a robust ORM-style syntax complete with models, relationships, filtering, includes and more. You only needs access to the resources store to be able to use the selector api.

Here is an example of using the ORM syntax to select from the store

Checklist.query(resources)
  .where({ active: true })
  .includes(['tasks'])
  .toObjects()

What BlueChip Is Not

Fetching

BlueChip is not interested in how you get your data. Fetch it, mock it, import it. However you get your data that is your business. The only requirement is that your data is formatted according to one of the adapters (JsonAPI, GraphQL). If it is not formatted you can write a custom adapter to normalize it.

Client Side Store

BlueChip is agnostic to which client-side state management library you choose to use (Redux, Mobx, Vuex, other). You only need access to a shared resources store for BlueChip to work.

Why BlueChip?

  1. You have multiple data sources (or multiple projects with different data sources) and want to consistently interact with all of them in the same way in your client-side state management systems. You can easily normalize and connect components from GraphQL, JsonAPI and custom formatted API's.

  2. You would like to keep resources unnessted in your stores for ease of updating, simplicity of mutation schema and ability to easily share resources across your application.

  3. You already have a state manager that you like or is a requirement of a project and do not want to adopt multiple to handle both GraphQL and JSON Rest data.

You are familiar with and prefer using ORM's when querying and working with data.

Demos

Redux Demo

Demo BlueChip/Redux Applicaiton

MobX Demo

Demo BlueChip/Mobx Application

React setState Demo

Demo BlueChip/React setState Application

Unstated Demo

Demo Unstated Application

Getting Started

To start, choose your state management flavor. This is an example using Redux.

$ npm i -S @blue-chip/core $ npm i -S @blue-chip/redux-adapter

Or

yarn add @blue-chip/core yarn add @blue-chip/redux-adapter

Adapters

To ensure that BlueChip is as flexible as possible, the state managment layer is implemented as adapters. These adapters are what do the work to mutate the state managment stores while BlueChip is in charge of delegating. To use the adapters you will need to setup a configuration file.

Configuration

The configuration file needs to be setup so that you can import and use the mutator actions.

import { Actions } from "@blue-chip/core";
import reduxAdapter from "@blue-chip/redux-adapter";
import store from "./store";

export const actions = Actions.config({
  adapter: reduxAdapter,
  mutator: store.dispatch
});

Redux

Actions

Batch update resources:

import { actions } from "../BlueChipConfig";

export const fetchChecklists = async (dispatch, state) => {
  dispatch({ type: "LOADING_DATA" });
  try {
    const response = await fetch("/checklists.json", {
      headers: {
        "content-type": "application/json"
      }
    });
    const payload = await response.json();

    actions.updateResources(payload);
    dispatch({ type: "LOADING_SUCCESS" });
  } catch (error) {
    console.log("error", error);
    dispatch({ type: "LOADING_ERROR" });
  }
};

Update a single resource

import { actions } from "../BlueChipConfig";

export const updateTask = ({ id, ...attributes }) => {
  actions.updateResource({ id, attributes, type: "tasks" });
};

Reducers

import { combineReducers } from "redux";
import reduxAdapter from "@blue-chip/redux-adapter";

export default combineReducers({
  resources: reduxAdapter.resourcesReducer
});

Models

Just like any other ORM you will be defining model classes:

import { BaseModel } from "@blue-chip/core";
import Task from "./Task";

export default class Checklist extends BaseModel {
  static get hasMany() {
    return [Task];
  }
}
import { BaseModel } from "@blue-chip/core";
import Checklist from "./Checklist";

export default class Task extends BaseModel {
  static get belongsTo() {
    return [Checklist];
  }
}

Containers

const mapStateToProps = state => { 
  const { resources } = state; 
  return { 
    checklists: Checklist.query(resources) 
                  .all() 
                  .includes(["tasks"]) 
                  .toObjects() 
  };
};

const mapDispatchToProps = dispatch => ({ 
  updateTask: task => updateTask(dispatch, task)
});

export default connect(mapStateToProps, mapDispatchToProps)(Container);

Store Structure

The resources store is structured as an object with top-level keys as pluralized resource names.

const store = {
  resources: {
    checklists: {},
    tasks: {}
  }
};

Each resource key points to an object that contains ids as keys and an JSON api object as a value.

const store = {
  checklists: {
    1: {
      id: 1,
      attributes: { name: "Oboarding" },
      links: { self: "http://example.com/checklists/1" },
      relationships: {
        tasks: {
         data: [{ id: 1, type: "tasks: }, { id: 2, type: "tasks: }],
       },
       type: "checklists"
    }
  },
  tasks: {
  ...
}  

Project Status

This project is currently in Alpha/Experimental phase. The APIs will almost assuredly change prior to 1.0. It is not ready for production yet, so use at your own risk.

RoadMap

  1. Increase Test Coverage
  2. Setup tests on CI
  3. More tests and examples with a diverse range of GraphQL and JsonAPI payloads.
  4. Refactor state managment to be an adapter as an external packages
  5. Add Vue and Vuex
  6. Allow for configurable and custom normailzers so you can use ANY api and spec.
  7. Bundle optimization
  8. belongsTo relationship
  9. Memoization
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].