@appsflow/redux
Advanced tools
Comparing version 0.0.0-alpha.9 to 0.0.0-alpha.10
@@ -6,7 +6,7 @@ /** | ||
import $flow from "@appsflow/core"; | ||
import { PreloadedState, ReducersMapObject, Slice } from '@reduxjs/toolkit'; | ||
export declare abstract class Controller extends $flow.Controller { | ||
import { EmptyObject, PreloadedState, Slice, SliceCaseReducers } from '@reduxjs/toolkit'; | ||
export declare class Controller extends $flow.Controller { | ||
private routes; | ||
readonly slice: Slice | undefined; | ||
protected constructor(); | ||
readonly slice: Slice; | ||
constructor(); | ||
static getName(): string; | ||
@@ -17,8 +17,17 @@ static getSliceInitialState(): any; | ||
register(): void; | ||
getCommands(): { | ||
[p: string]: any; | ||
}; | ||
getData(): { | ||
[p: string]: any; | ||
}; | ||
getInternal(): { | ||
[p: string]: any; | ||
}; | ||
getRoutes(): {}; | ||
getReducers(): ReducersMapObject; | ||
getSlice(): Slice; | ||
getState(): PreloadedState<any>; | ||
getReducers(): SliceCaseReducers<any>; | ||
getSlice(): Slice<PreloadedState<any>, SliceCaseReducers<any>, string>; | ||
getState(): PreloadedState<EmptyObject>; | ||
private createSlice; | ||
} | ||
export default Controller; |
@@ -8,7 +8,4 @@ import React from "react"; | ||
export declare function getStore(): any; | ||
declare const managers: { | ||
routes: Routes; | ||
}; | ||
export declare function getRoutes(): Routes; | ||
export { Routes }; | ||
export { Controller }; | ||
export { managers }; |
@@ -0,7 +1,13 @@ | ||
import { PayloadAction } from '@reduxjs/toolkit'; | ||
import { commandBases } from '@appsflow/core'; | ||
import Controller from "../controller"; | ||
export declare const store: import("redux").Store<{ | ||
export declare const routesSlice: import("@reduxjs/toolkit").Slice<{ | ||
current: string; | ||
history: string[]; | ||
}, import("redux").AnyAction>; | ||
}, { | ||
set(state: import("immer/dist/internal").WritableDraft<{ | ||
current: string; | ||
history: string[]; | ||
}>, action: PayloadAction<string>): void; | ||
}, "routes">; | ||
declare const Routes_base: typeof import("@appsflow/core/dist/es/src/managers").Commands; | ||
@@ -12,3 +18,5 @@ export declare class Routes extends Routes_base { | ||
}; | ||
get history(): string[]; | ||
private store; | ||
constructor(store: any); | ||
get history(): any; | ||
static getName(): string; | ||
@@ -15,0 +23,0 @@ watch(callback: () => any): void; |
{ | ||
"name": "@appsflow/redux", | ||
"version": "0.0.0-alpha.9", | ||
"version": "0.0.0-alpha.10", | ||
"description": "AppFlow redux", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -6,3 +6,9 @@ /** | ||
import $flow, { errors } from "@appsflow/core"; | ||
import { createSlice, PreloadedState, ReducersMapObject, Slice, } from '@reduxjs/toolkit'; | ||
import { | ||
createSlice, | ||
EmptyObject, | ||
PreloadedState, | ||
Slice, | ||
SliceCaseReducers, | ||
} from '@reduxjs/toolkit'; | ||
@@ -14,3 +20,3 @@ export class Controller extends $flow.Controller { | ||
constructor() { | ||
public constructor() { | ||
super(); | ||
@@ -23,5 +29,2 @@ | ||
} | ||
this.initialize(); | ||
} | ||
@@ -51,5 +54,17 @@ | ||
// @ts-ignore | ||
this.routes = window.$flow.managers.routes.register( routes, this ); | ||
this.routes = managers.routes.register( routes, this ); | ||
} | ||
getCommands(): { [ p: string ]: any } { | ||
return super.getCommands(); | ||
} | ||
getData(): { [ p: string ]: any } { | ||
return super.getData(); | ||
} | ||
getInternal(): { [ p: string ]: any } { | ||
return super.getInternal(); | ||
} | ||
getRoutes() { | ||
@@ -59,13 +74,12 @@ return {}; | ||
getReducers(): ReducersMapObject { | ||
getReducers(): SliceCaseReducers<any> { | ||
throw new errors.ForceMethod( this, 'getReducers' ); | ||
} | ||
getSlice() { | ||
getSlice(): Slice<PreloadedState<any>, SliceCaseReducers<any>, string> { | ||
return this.slice; | ||
} | ||
getState(): PreloadedState<any> { | ||
// @ts-ignore | ||
return $flow.store.getState()[ this.getName() ]; | ||
getState(): PreloadedState<EmptyObject> { | ||
throw new errors.ForceMethod( this, 'getState' ); | ||
} | ||
@@ -79,3 +93,3 @@ | ||
initialState: currentConstructor.getSliceInitialState(), | ||
reducers: this.getReducers(), | ||
reducers: this.getReducers() | ||
} ); | ||
@@ -82,0 +96,0 @@ } |
@@ -5,7 +5,5 @@ import React from "react"; | ||
import { Routes} from "./managers/routes"; | ||
import { Routes, routesSlice } from "./managers/routes"; | ||
import { Controller } from "./controller"; | ||
const routes = new Routes(); | ||
export const useCurrentRoute = ( prefix:string ) => { | ||
@@ -42,2 +40,4 @@ // eslint-disable-next-line no-undef | ||
let routes: Routes | undefined = undefined; | ||
export function getStore(): any { | ||
@@ -57,2 +57,4 @@ if ( store ) { | ||
reducer[ routesSlice.name ] = routesSlice.reducer; | ||
store = configureStore( { reducer } ) | ||
@@ -63,4 +65,10 @@ | ||
const managers = { | ||
routes, | ||
export function getRoutes() { | ||
if ( routes ) { | ||
return routes; | ||
} | ||
routes = new Routes( getStore() ); | ||
return routes; | ||
} | ||
@@ -70,2 +78,1 @@ | ||
export { Controller } | ||
export { managers } |
@@ -1,3 +0,3 @@ | ||
import { createStore } from "redux"; | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit' | ||
import { EnhancedStore } from "@reduxjs/toolkit/src/configureStore"; | ||
@@ -8,10 +8,8 @@ import $flow, { commandBases } from '@appsflow/core'; | ||
const initState = { | ||
current: 'default', | ||
history: Array<string>(), | ||
} | ||
const slice = createSlice( { | ||
export const routesSlice = createSlice( { | ||
name: "routes", | ||
initialState: initState, | ||
initialState: { | ||
current: 'default', | ||
history: Array<string>(), | ||
}, | ||
reducers: { | ||
@@ -25,10 +23,15 @@ set( state, action: PayloadAction<string> ) { | ||
export const store = createStore( slice.reducer ) | ||
export class Routes extends $flow.managers().Commands { | ||
public currentRoute: { [ key: string ]: string } = {}; | ||
private store: EnhancedStore<any, any, any>; | ||
constructor( store: any ) { | ||
super(); | ||
this.store = store; | ||
} | ||
get history() { | ||
// Get from store. | ||
return store.getState().history; | ||
return this.store.getState().history; | ||
} | ||
@@ -42,3 +45,3 @@ | ||
watch( callback: () => any ) { | ||
store.subscribe( callback ); | ||
this.store.subscribe( callback ); | ||
} | ||
@@ -45,0 +48,0 @@ |
Sorry, the diff of this file is too big to display
126567
2975