Skip to content

Commit

Permalink
Services class + navio service added
Browse files Browse the repository at this point in the history
  • Loading branch information
kanzitelli committed Oct 1, 2022
1 parent 537bcc5 commit 642afad
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/services/index.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
import React from 'react';

import {OnStartService} from './onStart';
import {NavService} from './navigation';
import {TranslateService} from './translate';
import {ApiService} from './api';
import {getNavio} from '../screens';

export const services = {
t: new TranslateService(), // should be first
nav: new NavService(),
onStart: new OnStartService(),
api: new ApiService(),
};
type ContextServices = typeof services;
class Services {
t = new TranslateService();
onStart = new OnStartService();
api = new ApiService();

// -- adding navio as a service
get navio() {
return getNavio();
}
}
export const services = new Services();

const servicesContext = React.createContext<ContextServices>(services);
const servicesContext = React.createContext<Services>(services);
export const ServicesProvider = ({children}: any) => (
<servicesContext.Provider value={services}>{children}</servicesContext.Provider>
);

export const useServices = (): ContextServices => React.useContext(servicesContext);
export const useServices = (): Services => React.useContext(servicesContext);

export const initServices = async (): PVoid => {
for (const key in services) {
if (Object.prototype.hasOwnProperty.call(services, key)) {
const s = (services as Services)[key];
const s = (services as any)[key] as IService;

if (s.init) {
await s.init();
Expand Down

0 comments on commit 642afad

Please sign in to comment.