0.11.0 • Published 1 year ago

spot-store v0.11.0

Weekly downloads
137
License
SEE LICENSE IN LI...
Repository
github
Last release
1 year ago

Spot

Node.js CI

Installing

npm install spot-store

Example

See code in the example directory for a sample usage (and a naive dummy backend)

  // Initialize client with a base url 
  const spot = initializeSpot(apiBaseUrl);
  
  // Query a list endpoint and store the results under 'users'
  await spot.query('fetch-users', {}, ['users']);

  // Access the data
  spot.data.users['id-one'].name
  
  // Send a command to update a user
  await spot.command('update-user', { userId: 'id-one', age: 7 }, /* OPTIONAL */ { method: 'POST' });

  // Query a specific user and override the user stored at 'users/id-one'
  spot.query('fetch-user', { userId: 'id-one' }, ['users', 'id-one']);

  // Instead of awaiting you can also use subscription callback
  spot.subscribeOnce(() => {
    // Access the stored data
    spot.data.users['id-one'].name;
  })
  

Listing approach

To use list results from an api, a convenient method is to use a dictionary with the IDs as the keys. This allows for convenient fetching in the form of:

  await spot.query('fetch-users', {}, ['users']);

assuming the data returned is something like:

[
  "id-one": { 
    "name": "Spot",
    "age": 7
  },
  "id-two": { 
    "name": "Rufus",
    "age": 4
  }
]

Contributing

Pull Requests are always welcome!

License

Note that this is not free software if you are a company with a high enough revenue. Please see License.md.

0.11.0

1 year ago

0.10.0

1 year ago

0.9.5

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.0

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.8.0

3 years ago

0.8.0-alpha.1

3 years ago

0.7.0

3 years ago

0.7.0-alpha.9

3 years ago

0.6.0

4 years ago

0.6.0-alpha.1

4 years ago

0.6.0-alpha.2

4 years ago

0.4.0-alpha.2

4 years ago

0.5.0

4 years ago

0.4.0

4 years ago

0.4.0-alpha.1

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.7

4 years ago

0.0.1

4 years ago