0.4.0-alpha • Published 3 years ago

lbrx v0.4.0-alpha

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

LbrX - alpha version

This is an object oriented State Manager that's build for JavaScript applications that's based on RxJs. The api for querying the data is very similar to .Net EF LINQ but with observables. State updates can also be achieved with partial objects and we will merge the objects for you. Object instance preservation guaranteed if you're working with classes or dates. Unlinked object references guaranteed even with deep nested objects, no changes will apply to your state unintentionally. Two way data flow with no boilerplate code! We also support Redux DevTools for easier state debugging.

Development progress

  • Single object store
  • Class support
  • Local or session storage configuration per store
  • Reset-able stores support
  • Object compare configuration per store support for better performance with very large objects
  • Store hooks
  • Redux DevTools one way support
  • Redux DevTools both ways support
  • Deep nested objects support
  • Global default store configurations
  • Async initialization support (Promise and Observable)
  • Serialization and denationalization configuration for browser storage
  • NgZone Support
  • ES5 support
  • Multi platform support, including Node.JS
  • LbrX utility functions available for import
  • Store pause api
  • Store destroy api
  • Advanced store config that allows methods override like objectClone, objectCompare, etc.
  • Select with string literals
  • Full spec coverage of the above
  • List Store - wip
  • Full spec coverage of the above
  • Playground
  • Full documentation

Important Notice

  • Added support for moment.js.
  • LbrX utility functions and types are now available via import { ... } from 'lbrx/utils'.
  • storeName.select() is removed. Use: storeName.select$().
  • Global error store has bee removed.
  • Hook's interfaces have been removed. Now you can just override the methods in the inheritor class.
  • LbrXManager should now be imported from lbrx/core.
  • DevtoolsOptions should now be imported from lbrx/dev-tools.

Dependencies

  • RxJS 6.5.4 or higher.

Installation

npm i lbrx rxjs

CDN

URLESMinified
https://cdn.jsdelivr.net/npm/lbrx@0.4.0-alpha/bundles/lbrx.umd.jsES2015No
https://cdn.jsdelivr.net/npm/lbrx@0.4.0-alpha/bundles/lbrx.umd.min.jsES2015Yes
https://cdn.jsdelivr.net/npm/lbrx@0.4.0-alpha/bundles/lbrx.umd.es5.jsES5No
https://cdn.jsdelivr.net/npm/lbrx@0.4.0-alpha/bundles/lbrx.umd.es5.min.jsES5Yes

Example

Step 1: Initialization

import { LbrXManager, StoreConfig, Store, Storages } from "lbrx";

const PROD_MODE = false;
if (PROD_MODE) LbrXManager.enableProdMode();
LbrXManager.initializeDevTools();

class Address {
  place: string | null = null;
}

class User {
  firstName: string | null = null;
  lastName: string | null = null;
  address: Address | null = null;
}

function createLeon(): User {
  return Object.assign(new User(), {
    firstName: "Leon",
    address: Object.assign(new Address(), {
      place: "Hell of a place",
    }),
  });
}

Step 2: Create Store

@StoreConfig({
  name: "LEON-STORE",
  objectCompareType: ObjectCompareTypes.advanced,
  isResettable: true,
  storageType: Storages.session,
  storageDebounceTime: 500,
})
class UserStore extends Store<User> {
  constructor() {
    super(createLeon());
  }
}

const userStore = new UserStore();

Step 3: Subscribe to changes

userStore.select$().subscribe((x) => console.log(x));
userStore
  .select$((state) => state.firstName)
  .subscribe((x) => console.log("firstName: " + x));
userStore
  .select$((state) => state.lastName)
  .subscribe((x) => console.log("lastName: " + x));
userStore
  .select$((state) => state.address?.place)
  .subscribe((x) => console.log("address: " + x));

// User {firstName: "Leon", lastName: null, address: Address}
// firstName: Leon
// lastName: null
// address: Hell of a place

Step 4: Update Store

Pay attention to the values that haven't been changed. They won't trigger their subscribers, thus preventing unnecessary performance hit.

setTimeout(() => {
  userStore.update({
    firstName: "Some other name",
    lastName: "My first lastName",
  });
}, 200);

// User {firstName: "Some other name", lastName: "My first lastName", address: Address}
// firstName: Some other name
// lastName: My first lastName

setTimeout(() => {
  userStore.update({
    firstName: "Some other name",
    lastName: "My second lastName",
    address: {
      place: "Some other place",
    },
  });
}, 500);

// User {firstName: "Some other name", lastName: "My second lastName", address: Address}
// lastName: My second lastName
// address: Some other place

setTimeout(() => {
  userStore.reset();
}, 500);

// User {firstName: "Leon", lastName: null, address: Address}
// firstName: Leon
// lastName: null
// address: Hell of a place

setTimeout(() => {
  userStore.reset();
}, 550);

// NOTHING will print ( because the state didn't change. )

Step 5: Debug using Redux DevTools

ReduxDevTools

Browser Support

  • All current browsers (major versions from the last 2 years) are supported.
  • Node.JS support.
  • Source files are included in 'node_modules\lbrx\src'.
  • UMD bundles* are included in 'node_modules\lbrx\bundles'.
  • IE11** ES5 syntax support.

* Both ES5 and ES2015 UMD bundles are included and both have minified and non minified versions. In all bundles the global would be lbrx.

** For IE11 you may need additional polyfills but if you're using a framework, they may already be included.

Licence

0.4.0-alpha

3 years ago

0.3.9-alpha

3 years ago

0.3.8-alpha

3 years ago

0.3.7-alpha

4 years ago

0.3.6-alpha

4 years ago

0.3.5-alpha

4 years ago

0.3.4-alpha

4 years ago

0.3.3-alpha

4 years ago

0.3.2-alpha

4 years ago

0.3.1-alpha

4 years ago

0.3.0-alpha

4 years ago

0.2.9-alpha

4 years ago

0.2.7-alpha

4 years ago

0.2.8-alpha

4 years ago

0.2.5-alpha

4 years ago

0.2.6-alpha

4 years ago

0.2.4-alpha

4 years ago

0.2.3-alpha

4 years ago

0.2.2-alpha

4 years ago

0.2.1-alpha

4 years ago

0.2.0-alpha

4 years ago

0.1.9-alpha

4 years ago

0.1.8-alpha

4 years ago

0.1.6-alpha

4 years ago

0.1.5-alpha

4 years ago

0.1.7-alpha

4 years ago

0.1.3-alpha

4 years ago

0.1.4-alpha

4 years ago

0.1.2-alpha

4 years ago

0.1.1-alpha

4 years ago

0.1.0-alpha

4 years ago