From f35edf0297d82177b23a73222b606511a50d9cf9 Mon Sep 17 00:00:00 2001 From: Tim Glasgow Date: Sun, 31 Jul 2022 12:49:48 -0500 Subject: [PATCH] code conventions --- changeme/{Launcher.js => Main.js} | 0 changeme/__tests__/DB-test.js | 20 ++++++++++---------- changeme/index.js | 8 ++++---- changeme/src/navigation/MainNav.js | 4 ++-- changeme/src/navigation/MainStack.js | 4 ++-- changeme/src/realm/{dbAPI.js => DbAPI.js} | 8 ++++---- changeme/src/realm/{dbInit.js => DbInit.js} | 0 changeme/src/redux/actions/SystemActions.js | 15 +++++++-------- changeme/src/redux/reducers/SystemReducer.js | 6 +++++- 9 files changed, 34 insertions(+), 31 deletions(-) rename changeme/{Launcher.js => Main.js} (100%) rename changeme/src/realm/{dbAPI.js => DbAPI.js} (83%) rename changeme/src/realm/{dbInit.js => DbInit.js} (100%) diff --git a/changeme/Launcher.js b/changeme/Main.js similarity index 100% rename from changeme/Launcher.js rename to changeme/Main.js diff --git a/changeme/__tests__/DB-test.js b/changeme/__tests__/DB-test.js index 09c6dbe..b270b97 100644 --- a/changeme/__tests__/DB-test.js +++ b/changeme/__tests__/DB-test.js @@ -1,5 +1,5 @@ -import { initDB } from '../src/realm/dbInit'; -import dbAPI from '../src/realm/dbAPI'; +import { initDB } from '../src/realm/DbInit'; +import DbAPI from '../src/realm/DbAPI'; test('Realm DB inits', () => { return initDB('negTest', 'negTest') @@ -29,34 +29,34 @@ test('Realm DB returns null after exceptions', () => { }); }); -test('dbAPI calls system repo getAllSystemValues()', () => { +test('DbAPI calls system repo getAllSystemValues()', () => { return initDB('isNull', 'isNull') .then( () => { - let returned = dbAPI.getAllSystemValues(); + let returned = DbAPI.getAllSystemValues(); expect(returned).toEqual({}); }); }); -test('dbAPI calls system repo createSystemValue()', () => { +test('DbAPI calls system repo createSystemValue()', () => { return initDB('isNull', 'isNull') .then( () => { - let returned = dbAPI.createSystemValue(); + let returned = DbAPI.createSystemValue(); expect(returned).toEqual(true); }); }); -test('dbAPI calls system repo deleteSystemValue()', () => { +test('DbAPI calls system repo deleteSystemValue()', () => { return initDB('isNull', 'isNull') .then( () => { - let returned = dbAPI.deleteSystemValue(); + let returned = DbAPI.deleteSystemValue(); expect(returned).toEqual(true); }); }); -test('dbAPI calls system repo getSystemValue()', () => { +test('DbAPI calls system repo getSystemValue()', () => { return initDB('isNull', 'isNull') .then( () => { - let returned = dbAPI.getSystemValue('notakey'); + let returned = DbAPI.getSystemValue('notakey'); expect(returned.id).toEqual(null); }); }); \ No newline at end of file diff --git a/changeme/index.js b/changeme/index.js index 33df663..df3ea11 100644 --- a/changeme/index.js +++ b/changeme/index.js @@ -1,12 +1,12 @@ import React from 'react'; import {AppRegistry} from 'react-native'; import {name as appName} from './app.json'; -import MainComponent from './Launcher'; -import configStore from './src/redux/CreateStore'; +import MainComponent from './Main'; +import ConfigStore from './src/redux/CreateStore'; import { appInit } from './src/redux/actions/SystemActions'; -const store = configStore; -store.dispatch(appInit()); +const store = ConfigStore; +ConfigStore.dispatch(appInit()); const ProppedContainer = () => { return ; diff --git a/changeme/src/navigation/MainNav.js b/changeme/src/navigation/MainNav.js index 40f7537..9cb8104 100644 --- a/changeme/src/navigation/MainNav.js +++ b/changeme/src/navigation/MainNav.js @@ -1,8 +1,8 @@ import { createRef } from "react"; -export const mainRef = createRef(); +export const MainRef = createRef(); export function navigate(name, params) { - mainRef.current?.navigate(name, params); + MainRef.current?.navigate(name, params); return true; } \ No newline at end of file diff --git a/changeme/src/navigation/MainStack.js b/changeme/src/navigation/MainStack.js index 69d068f..eed2af6 100644 --- a/changeme/src/navigation/MainStack.js +++ b/changeme/src/navigation/MainStack.js @@ -1,7 +1,7 @@ import React from 'react'; import {NavigationContainer} from '@react-navigation/native'; import {createStackNavigator} from '@react-navigation/stack'; -import {mainRef} from './MainNav'; +import {MainRef} from './MainNav'; import Home from '../screens/Home'; import Settings from '../screens/Settings'; @@ -13,7 +13,7 @@ function MainStack() { let noHeader = {headerShown: false}; return ( - + { - await dbAPI.initDB(); + await DbAPI.initDB(); dispatch(onInit()); } } function onInit() { - return (dispatch) => { + return (dispatch, getState) => { + let system = getState().system; dispatch({ - type: APP_INIT - //system: system - //user: user - //score: score + type: APP_INIT, + system: system }); } } \ No newline at end of file diff --git a/changeme/src/redux/reducers/SystemReducer.js b/changeme/src/redux/reducers/SystemReducer.js index 013edc1..bea1586 100644 --- a/changeme/src/redux/reducers/SystemReducer.js +++ b/changeme/src/redux/reducers/SystemReducer.js @@ -1,6 +1,10 @@ import { APP_INIT } from "../types/SystemTypes"; -function sys(state = {}, action) { +const initialState = { + dbLoaded: false +}; + +function sys(state = initialState, action) { switch (action.type) { case APP_INIT: return {...state, ...action.system};