Numbers Prefer Multiplication
Miss any of our Open RFC calls?Watch the recordings here! »

@data-provider/memory

2.0.4 • Public • Published

Build status Coverage Status Quality Gate Mutation testing badge

NPM dependencies Renovate Last commit Last release

NPM downloads License

Memory origin addon for Data Provider

It provides CRUD methods for objects saved in memory.

Usage

Read the Data Provider docs to learn how to use addons.

Queries

When querying providers created with this addon, the query object can have one of the next properties:

  • prop (String): Specific property of the object to be accessed.

Example

import { Memory } from "@data-provider/memory";
 
const sessionStatus = new Memory("session-status", {
  initialState: {
    data: {
      loggedIn: false
    }
  }
});
 
sessionStatus.query({ prop: "loggedIn" }).update(true);
sessionStatus.query({ prop: "loggedIn" }).read().then(result => {
  console.log("Is logged in", result);
  // true
});

Custom methods

Apart of the common Data Provider methods, next ones are available:

update(data)

Updates an specific property of the stored object when the provider is queried, or the full object when not. When the object is modified, it will automatically cleans the cache of the provider and also the cache of the parent provider when it is queried (as modifying a property also modifies the full object).

Arguments

  • data (Any): New data to be set.

Examples

// modifies an specific property
sessionStatus.query({ prop: "loggedIn" }).update(true);
// Overwrites full object
sessionStatus.update({
  loggedIn: true
});

delete()

Removes an specific property of the stored object when the provider is queried, or sets the full object as empty when not. When the object is modified, it will automatically cleans the cache of the provider and also the cache of the parent provider when it is queried (as deleting a property also modifies the full object).

Examples

// removes an specific property
sessionStatus.query({ prop: "loggedIn" }).delete();
// Sets the full object as {}
sessionStatus.delete();

Contributing

Contributors are welcome. Please read the contributing guidelines and code of conduct.

Install

npm i @data-provider/memory

DownloadsWeekly Downloads

800

Version

2.0.4

License

Apache-2.0

Unpacked Size

37.6 kB

Total Files

8

Last publish

Collaborators

  • avatar