Comments (8)
Ignite 7.15 is quite old, is this a new project or one that's been around for some time?
If the latter, if you could provide a snippet of what you have that would be helpful.
If it's a new project and you're just starting out, I'd try using the latest version and see if you run into the same issue.
from ignite.
@frankcalise It's a new project and Sorry ignite version is 9.2.0
So Let me add some details.
Let's suppose I am using the same code of boilerplate
This is my AuthenticationStore file
import { Instance, SnapshotOut, types } from "mobx-state-tree"
export const AuthenticationStoreModel = types
.model("AuthenticationStore")
.props({
authToken: types.maybe(types.string),
authEmail: "",
})
.views((store) => ({
get isAuthenticated() {
return !!store.authToken
},
}))
.actions((store) => ({
setAuthToken(value?: string) {
store.authToken = value
}
}))
export interface AuthenticationStore extends Instance<typeof AuthenticationStoreModel> {}
export interface AuthenticationStoreSnapshot extends SnapshotOut<typeof AuthenticationStoreModel> {}
And This is my EpisodeStore file
import { Instance, SnapshotOut, types } from "mobx-state-tree"
import { api } from "../services/api"
import { Episode, EpisodeModel } from "./Episode"
import { withSetPropAction } from "./helpers/withSetPropAction"
export const EpisodeStoreModel = types
.model("EpisodeStore")
.props({
episodes: types.array(EpisodeModel),
favorites: types.array(types.reference(EpisodeModel)),
favoritesOnly: false,
})
.actions(withSetPropAction)
.actions((store) => ({
async fetchEpisodes() {
// here I want to use action function `setAuthToken` from AuthenticationStore, How can I use here??
const response = await api.getEpisodes()
if (response.kind === "ok") {
store.setProp("episodes", response.episodes)
} else {
console.error(`Error fetching episodes: ${JSON.stringify(response)}`)
}
},
}))
export interface EpisodeStore extends Instance<typeof EpisodeStoreModel> {}
export interface EpisodeStoreSnapshot extends SnapshotOut<typeof EpisodeStoreModel> {}
In EpisodeStore file, I put a comment in action fetchEpisodes
, Here I want to use setAuthToken
from AuthenticationStore, How can I access this method??
Do I make my point clear??
from ignite.
@Zilleabbas10 hey, I think this Ignite Cookbook Recipe can help you out: https://ignitecookbook.com/docs/recipes/DistributingAuthTokenToAPI
from ignite.
@frankcalise In this example we are calling distributeAuthToken
function from AuthenticationStore
in a component. But in my case I need to call this distributeAuthToken
function in my another store directly.
from ignite.
@Zilleabbas10 So what that recipe does is, upon setting the API token, your api requests made in other stores will already have that info filled in for you. So you don't need to obtain it and pass it in every call in other stores
from ignite.
@Zilleabbas10 Let suppose I have a LoadingStore
file like the following
import { Instance, SnapshotOut, types } from "mobx-state-tree"
export const LoadingStoreModel = types
.model("LoadingStore")
.props({
isLoading: types.maybe(types.boolean),
})
.views((store) => ({
}))
.actions((store) => ({
setLoading(value?: boolean) {
store.isLoading = value
}
}))
export interface LoadingStore extends Instance<typeof LoadingStoreModel> {}
export interface LoadingStoreSnapshot extends SnapshotOut<typeof LoadingStoreModel> {}
I need to call the action of this loadingStore.setLoading(true)
before I call any API in some other store. How can I do this??
I think I am pretty more clear now??
from ignite.
You can get to other stores by first getting the root store using the included helper:
from ignite.
@frankcalise thanks man. This is what I was looking for. Really appreciated your help 👍
from ignite.
Related Issues (20)
- Screen and Splash Generator not working HOT 3
- Expo Go should not install expo-dev-client HOT 3
- App keep crashing when i do any changes HOT 3
- SyntaxError: Unexpected token '<' when running Jest HOT 9
- cli new fails due to undefined dependency (@expo/config-plugins) HOT 1
- Missing translation HOT 4
- cannot create a project HOT 3
- Error when running `pod install` in the `ios` directory. HOT 3
- Missing translation error with 9.4.2 HOT 1
- Toggle "switch" variant does not slide on web HOT 4
- [Enhancement] v10 - Remove Expo Go compatibility HOT 1
- [Enhancement] v10 - Replace async storage with mmkv HOT 3
- [Enhancement] v10 - Refactor Toggle HOT 4
- reportCrash shows up in Sentry
- Creating bare react native project without expo HOT 5
- Update boilerplate/README.md HOT 1
- Add Social Preview to GitHub Settings
- Generic function load in storage [boilerplate] HOT 1
- Add responsive sizing to custom <Text /> component HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ignite.