feature: context from multiple sources
Closed this issue · 1 comments
On branch feature/multiSrcContext
I need the following only if possible and correct to do it that way. I want a few different sources of information in one single dataCtx
context.
If you know that my concept of "context" is wrong and should not be used in one of the following cases, then tell me, and show me how to do it without context:
- If possible: get both en/placesData and en/appData into a single context, and show me how to use both in some component somewhere (where that palcesData element and appData element are used.) - if time alows I'll give an example of where I want to use it.
- If not possible to load both into one context, show me how to load two contexts, one for placeData and one for appData.
- Get a state that is changed from the api to be in the context, so that I get to it from anywhere in the app, and so that a change of state causes an update anywhere in the app. Do it with
Now facing:
in pages/ThisWay.js or pages/tab_pages/ThiswayView.js (renamed from "place.js")
For change language I did some changes in the folder data, I added an index.
see: data/Index.js for more comments, there I added the function of getLanguage(languageCode), that returns the language that match the given languageCode.
The context languageDataCtx: contains: appData.json, placesData.json and stylesData.json of the current language (for default is en) using the function: getLanguage(languageCode).
- App.js is the Provider of the context, the context change between languages with the value: this.state.currentLanguage.
- Pages/AppMain.js is a Consumer of the the context, there in the render I print: appData, placesData and stylesData of the current Language.
The context placeDataCtx: contains the data of the current place, inside placesData there is an Array called Places, placeDataCtx loads the place with the given index.
- Pages/AppMain.js is the Provider of the context, the context change between places with the value: this.state.placeIndex.
- Pages/tab_pages/pointLists/PlacePoints.js is the Consumer of the context, there I print: place that represent the current place, and used the inPlace array of the current place to show it