Gathering detailed insights and metrics for mobx-keystone-asyncstore
Gathering detailed insights and metrics for mobx-keystone-asyncstore
Gathering detailed insights and metrics for mobx-keystone-asyncstore
Gathering detailed insights and metrics for mobx-keystone-asyncstore
An opinionated asynchronous store and container implementation for mobx-keystone.
npm install mobx-keystone-asyncstore
Typescript
Module System
TypeScript (89.71%)
JavaScript (10.29%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
4 Stars
86 Commits
1 Forks
1 Watchers
2 Branches
1 Contributors
Updated on Dec 30, 2024
Latest Version
0.5.2
Package Id
mobx-keystone-asyncstore@0.5.2
Unpacked Size
47.88 kB
Size
10.38 kB
File Count
12
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
30
An opinionated asynchronous store and container implementation for mobx-keystone.
⚠️WARNING: This library is under development and not yet considered stable. Use with caution as breaking changes to the API may be introduced until reaching v1.
One of the most common challenges when implementing a store solution is how to handle asynchronous data sets. mobx-keystone-asyncstore aims to simplify this by allowing you to create powerful asynchronous stores with just a few lines of code. An mobx-keystone-asyncstore implements the most common fetch patterns and support fetch queues, fail states and time to live out of the box.
Let's look at a simple implementation of a TodoStore:
1import axios from "axios"; 2import { when } from "mobx"; 3import { model, modelAction, Model, tProp, types } from "mobx-keystone"; 4import { AsyncStore } from "mobx-keystone-asyncstore"; 5 6// Create main model 7@model("models/TodoItem") 8class TodoItem extends Model({ 9 id: tProp(types.string), 10 task: tProp(types.string), 11 done: tProp(types.boolean, false), 12}) { 13 @modelAction 14 public toggleDone() { 15 this.done = !!this.done; 16 } 17} 18 19// Create async store 20const storeName = "stores/TodoStore"; 21@model(storeName) 22class TodoStore extends AsyncStore( 23 TodoItem, 24 { 25 name: storeName, 26 // Logic to fetch one item 27 async fetchOne(id: string) { 28 const res = await axios.get(`/todos/${id}`); 29 return new TodoItem(res.data); 30 }, 31 // Logic to fetch many items 32 async fetchMany(ids: string[]) { 33 const res = await axios.get(`/todos`, { ids }); 34 return res.data.response.map((d: any) => new TodoItem(d)); 35 }, 36 // Logic to fetch all items 37 async fetchAll() { 38 const res = await axios.get(`/todos/all`); 39 return res.data.response.map((d: any) => new TodoItem(d)); 40 }, 41 }, 42 { 43 // Add additional model props for the store 44 isDirty: tProp(types.boolean, true), 45 } 46) { 47 @modelAction 48 public setDirty(isDirty = true) { 49 this.isDirty = isDirty; 50 } 51 52 // Add additional methods for the store 53 @modelAction 54 public addTodo(task: TodoItem) { 55 // Create container that will contain our task 56 const container = this.createAsyncContainer(task.id); 57 // Add task to container value 58 container.setValue(task); 59 // Add container to store 60 this.containers.set(task.id, container); 61 // Set the store as dirty 62 this.setDirty(); 63 // Let's return the container so it may be used 64 return container; 65 } 66 67 // Method to save all our todos 68 async saveToDb() { 69 if (this.isDirty) { 70 const res = await axios.post(`/todos`, this.values); 71 if (res.status === 200) { 72 this.setDirty(false); 73 } 74 } 75 } 76} 77 78// Create store instance 79const todoStore = new TodoStore({}); 80 81// Ask the store to return container with id 'foo' 82const container = todoStore.getOne("foo"); 83 84// Wait for the container to be ready to be consumed 85when( 86 () => container.isReady, 87 () => { 88 const todo = container.value; 89 // todo is an instance of TodoItem 90 todo.toggleDone(); 91 } 92); 93 94// Add a new todo to the store 95todoStore.addTodo( 96 new TodoItem({ 97 id: "bar", 98 task: "Do this thing as well", 99 }) 100); 101 102// Use our custom save method 103todoStore.saveToDb();
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
64 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More