-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added TradingStrategyStore using RootStore pattern in preparation to …
…handle user click events
- Loading branch information
Showing
14 changed files
with
171 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { TradingStrategyStore } from "./TradingStrategyStore" | ||
import api from "./api" | ||
|
||
export class RootStore { | ||
tradingStrategyStore: TradingStrategyStore | ||
|
||
constructor() { | ||
this.tradingStrategyStore = new TradingStrategyStore(this, api); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { ReactNode, createContext, useContext } from "react"; | ||
import {RootStore} from "./RootStore" | ||
|
||
// holds a reference to the store (singleton) | ||
let store: RootStore | ||
|
||
// create the context | ||
const StoreContext = createContext<RootStore | undefined>(undefined); | ||
|
||
// create the provider component | ||
export function RootStoreProvider({ children }: { children: ReactNode }) { | ||
//only create the store once ( store is a singleton) | ||
const root = store ?? new RootStore() | ||
|
||
return <StoreContext.Provider value={root}>{children}</StoreContext.Provider> | ||
} | ||
|
||
// create the hook | ||
export function useRootStore() { | ||
const context = useContext(StoreContext) | ||
if (context === undefined) { | ||
throw new Error("useRootStore must be used within RootStoreProvider") | ||
} | ||
|
||
return context | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { RootStore } from "./RootStore"; | ||
import { BackenedApi } from "./api"; | ||
import { makeAutoObservable, runInAction} from "mobx" | ||
import { FakeStrategyChartData } from "./components/layout/DummyData"; | ||
|
||
export interface ChartData { | ||
time: string, | ||
amount: number, | ||
amountHold: number | ||
} | ||
|
||
export class TradingStrategyStore | ||
{ | ||
root: RootStore; | ||
transport: BackenedApi; | ||
|
||
isLoading: boolean = false; | ||
data: ChartData[] = []; | ||
|
||
constructor(root: RootStore, transport: BackenedApi) { | ||
makeAutoObservable(this); | ||
|
||
this.root = root | ||
this.transport = transport; | ||
|
||
this.loadChartData(); | ||
} | ||
|
||
loadChartData() { | ||
this.isLoading = true; | ||
runInAction(() => { | ||
console.log(`Data length: ${FakeStrategyChartData.length}`); | ||
this.data = FakeStrategyChartData; | ||
this.isLoading = false; | ||
}) | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters