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 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);
});
});

8
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 <MainComponent {...{store: store}} />;

4
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;
}

4
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 (
<NavigationContainer ref={mainRef}>
<NavigationContainer ref={MainRef}>
<MainNav.Navigator initialRouteName="Splash">
<MainNav.Screen
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(){
this.systemRepo = null;
this.userRepo = null;
@ -31,5 +31,5 @@ class DbAPI {
}
}
const dbAPI = new DbAPI();
export default dbAPI;
const DbAPI = new DatabaseAPI();
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 dbAPI from "../../realm/dbAPI";
import { initDB } from "../../realm/DbInit";
import DbAPI from "../../realm/DbAPI";
import { APP_INIT } from "../types/SystemTypes";
export function appInit() {
return async (dispatch) => {
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
});
}
}

6
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};

Loading…
Cancel
Save