Browse Source

code conventions

pull/1/head
Tim Glasgow 2 years ago
parent
commit
f35edf0297
  1. 0
      changeme/Main.js
  2. 20
      changeme/__tests__/DB-test.js
  3. 8
      changeme/index.js
  4. 4
      changeme/src/navigation/MainNav.js
  5. 4
      changeme/src/navigation/MainStack.js
  6. 8
      changeme/src/realm/DbAPI.js
  7. 0
      changeme/src/realm/DbInit.js
  8. 15
      changeme/src/redux/actions/SystemActions.js
  9. 6
      changeme/src/redux/reducers/SystemReducer.js

0
changeme/Launcher.js → changeme/Main.js

20
changeme/__tests__/DB-test.js

@ -1,5 +1,5 @@
import { initDB } from '../src/realm/dbInit'; import { initDB } from '../src/realm/DbInit';
import dbAPI from '../src/realm/dbAPI'; import DbAPI from '../src/realm/DbAPI';
test('Realm DB inits', () => { test('Realm DB inits', () => {
return initDB('negTest', 'negTest') 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') return initDB('isNull', 'isNull')
.then( () => { .then( () => {
let returned = dbAPI.getAllSystemValues(); let returned = DbAPI.getAllSystemValues();
expect(returned).toEqual({}); expect(returned).toEqual({});
}); });
}); });
test('dbAPI calls system repo createSystemValue()', () => { test('DbAPI calls system repo createSystemValue()', () => {
return initDB('isNull', 'isNull') return initDB('isNull', 'isNull')
.then( () => { .then( () => {
let returned = dbAPI.createSystemValue(); let returned = DbAPI.createSystemValue();
expect(returned).toEqual(true); expect(returned).toEqual(true);
}); });
}); });
test('dbAPI calls system repo deleteSystemValue()', () => { test('DbAPI calls system repo deleteSystemValue()', () => {
return initDB('isNull', 'isNull') return initDB('isNull', 'isNull')
.then( () => { .then( () => {
let returned = dbAPI.deleteSystemValue(); let returned = DbAPI.deleteSystemValue();
expect(returned).toEqual(true); expect(returned).toEqual(true);
}); });
}); });
test('dbAPI calls system repo getSystemValue()', () => { test('DbAPI calls system repo getSystemValue()', () => {
return initDB('isNull', 'isNull') return initDB('isNull', 'isNull')
.then( () => { .then( () => {
let returned = dbAPI.getSystemValue('notakey'); let returned = DbAPI.getSystemValue('notakey');
expect(returned.id).toEqual(null); expect(returned.id).toEqual(null);
}); });
}); });

8
changeme/index.js

@ -1,12 +1,12 @@
import React from 'react'; import React from 'react';
import {AppRegistry} from 'react-native'; import {AppRegistry} from 'react-native';
import {name as appName} from './app.json'; import {name as appName} from './app.json';
import MainComponent from './Launcher'; import MainComponent from './Main';
import configStore from './src/redux/CreateStore'; import ConfigStore from './src/redux/CreateStore';
import { appInit } from './src/redux/actions/SystemActions'; import { appInit } from './src/redux/actions/SystemActions';
const store = configStore; const store = ConfigStore;
store.dispatch(appInit()); ConfigStore.dispatch(appInit());
const ProppedContainer = () => { const ProppedContainer = () => {
return <MainComponent {...{store: store}} />; return <MainComponent {...{store: store}} />;

4
changeme/src/navigation/MainNav.js

@ -1,8 +1,8 @@
import { createRef } from "react"; import { createRef } from "react";
export const mainRef = createRef(); export const MainRef = createRef();
export function navigate(name, params) { export function navigate(name, params) {
mainRef.current?.navigate(name, params); MainRef.current?.navigate(name, params);
return true; return true;
} }

4
changeme/src/navigation/MainStack.js

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import {NavigationContainer} from '@react-navigation/native'; import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack'; import {createStackNavigator} from '@react-navigation/stack';
import {mainRef} from './MainNav'; import {MainRef} from './MainNav';
import Home from '../screens/Home'; import Home from '../screens/Home';
import Settings from '../screens/Settings'; import Settings from '../screens/Settings';
@ -13,7 +13,7 @@ function MainStack() {
let noHeader = {headerShown: false}; let noHeader = {headerShown: false};
return ( return (
<NavigationContainer ref={mainRef}> <NavigationContainer ref={MainRef}>
<MainNav.Navigator initialRouteName="Splash"> <MainNav.Navigator initialRouteName="Splash">
<MainNav.Screen <MainNav.Screen
name="Splash" name="Splash"

8
changeme/src/realm/dbAPI.js → changeme/src/realm/DbAPI.js

@ -1,6 +1,6 @@
import {initDB} from './dbInit'; import {initDB} from './DbInit';
class DbAPI { class DatabaseAPI {
constructor(){ constructor(){
this.systemRepo = null; this.systemRepo = null;
this.userRepo = null; this.userRepo = null;
@ -31,5 +31,5 @@ class DbAPI {
} }
} }
const dbAPI = new DbAPI(); const DbAPI = new DatabaseAPI();
export default dbAPI; export default DbAPI;

0
changeme/src/realm/dbInit.js → changeme/src/realm/DbInit.js

15
changeme/src/redux/actions/SystemActions.js

@ -1,21 +1,20 @@
import { initDB } from "../../realm/dbInit"; import { initDB } from "../../realm/DbInit";
import dbAPI from "../../realm/dbAPI"; import DbAPI from "../../realm/DbAPI";
import { APP_INIT } from "../types/SystemTypes"; import { APP_INIT } from "../types/SystemTypes";
export function appInit() { export function appInit() {
return async (dispatch) => { return async (dispatch) => {
await dbAPI.initDB(); await DbAPI.initDB();
dispatch(onInit()); dispatch(onInit());
} }
} }
function onInit() { function onInit() {
return (dispatch) => { return (dispatch, getState) => {
let system = getState().system;
dispatch({ dispatch({
type: APP_INIT type: APP_INIT,
//system: system system: system
//user: user
//score: score
}); });
} }
} }

6
changeme/src/redux/reducers/SystemReducer.js

@ -1,6 +1,10 @@
import { APP_INIT } from "../types/SystemTypes"; import { APP_INIT } from "../types/SystemTypes";
function sys(state = {}, action) { const initialState = {
dbLoaded: false
};
function sys(state = initialState, action) {
switch (action.type) { switch (action.type) {
case APP_INIT: case APP_INIT:
return {...state, ...action.system}; return {...state, ...action.system};

Loading…
Cancel
Save