GithubHelp home page GithubHelp logo

jonathan002 / ngtsm Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 4.07 MB

A demo for a lightweight state management paradigm that focuses on performance

JavaScript 8.79% TypeScript 81.93% HTML 7.17% CSS 2.11%

ngtsm's Introduction

ngTSM (Angular Typescript State Management)

The Goal of ngTSM is to follow a paradim of protecting state for an application while only relying on Typescript to Type protect it.

  • It is light weight and doesn't require an extra library to be installed.
  • It does not use javascript runtime to protect state such as ngrx selectors.
  • The methods are traceable as typings are retained vs having to retype actions if you are using ngrx.
  • The paradim is less powerful than intercepting actions, although it should have state mutation be tracable in a linear way. Too much interceptions of an action may be hard to read and cause bugs.

The concept can be learned quickely as you only need to know Typescript and Angular.

One Barrel Per Module

  • A ngrx store can be represented as a ServiceBarrel.
  • Each Barrel Collects Services that Type protect readonly state and mutate state with methods (which acts as reducers and actions).
  • Components can DI the service Barrel and read state or mutate state. (See Project for example)

Can It Scale?

  • Ideally it should scale as much as angular scales since it is module based.

Advance User Guide

Share State with Hiearchy DI

  • To prevent Circular Dependency a DI naming guide has been created.
    • High
    • Medium (no prefix - starting point)
    • Low

Lower Prefix names can be DI into services that are prefixed higher.

For extreme cases the hiearchy names can continue with increments or decrements.

  • Highest{incrementNumber}
  • Highest
  • Higher
  • ...
  • Lower
  • Lowest
  • Lowest{decrementNumber}

Share State with SharedService

  • A private shared store service (hiearchy of lowest) can be attached to each feature barrel and be used privately between all the service of the feature barrel. It can be used to hold utilities such as shared state properties or contain observables to emit state changes. This should be used as a last resort if Hiearchy DI cannot do the job. The goal is to isolate state and mutation logic together as much as possible.

ngtsm's People

Contributors

jonathan002 avatar

Watchers

 avatar  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.