flow: fixes

This commit is contained in:
cha0s 2021-01-15 06:46:55 -06:00
parent 8ffcc2e7bb
commit 9495e0456a
15 changed files with 13284 additions and 11384 deletions

View File

@ -10,7 +10,7 @@ export const gatherWithLatus = (
context, context,
{ {
transformer = camelCase, transformer = camelCase,
}, } = {},
) => (latus) => ( ) => (latus) => (
Object.fromEntries(context.keys().map((path) => { Object.fromEntries(context.keys().map((path) => {
const M = context(path).default; const M = context(path).default;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
import {ensureUniqueReduction} from '@latus/core'; import {ensureUniqueReduction, gatherWithLatus} from '@latus/core';
import configureStore from './store'; import configureStore from './store';
@ -17,7 +17,13 @@ export default {
hooks: { hooks: {
'@latus/core/starting': async (latus) => { '@latus/core/starting': async (latus) => {
latus.set('%slices', await ensureUniqueReduction(latus, '@latus/redux/slices')); latus.set('%slices', await ensureUniqueReduction(latus, '@latus/redux/slices'));
latus.set('%store', await configureStore(latus)); const defaultState = 'client' === process.env.SIDE
? latus.get('@latus/redux/client.defaultState')
: {};
latus.set('%store', await configureStore(latus, {defaultState}));
}, },
'@latus/socket/packets': gatherWithLatus(
require.context('./packets', false, /\.js$/),
),
}, },
}; };

View File

@ -3,12 +3,9 @@ import {ensureUniqueReduction} from '@latus/core';
export default { export default {
hooks: { hooks: {
'@latus/http/plugins': async (req, latus) => ({ '@latus/http/plugins': async (req, latus) => ({
'@latus/redux/client': req '@latus/redux/client': {
? { defaultState: await ensureUniqueReduction(latus, '@latus/redux/defaultState', req),
defaultState: await ensureUniqueReduction(latus, '@latus/redux/defaultState', req), },
}
: {}
,
}), }),
}, },
}; };

View File

@ -3,7 +3,7 @@ import reduceReducers from 'reduce-reducers';
import effectsMiddleware from './effects'; import effectsMiddleware from './effects';
export default async function configureStore(latus) { export default async function configureStore(latus, {defaultState = {}}) {
const options = { const options = {
enhancers: [ enhancers: [
'@latus/redux/defaultEnhancers', '@latus/redux/defaultEnhancers',
@ -14,7 +14,6 @@ export default async function configureStore(latus) {
], ],
}; };
latus.invokeFlat('@latus/redux/store', options); latus.invokeFlat('@latus/redux/store', options);
const {defaultState} = latus.config['@latus/redux/client'];
const slices = latus.get('%slices'); const slices = latus.get('%slices');
const reducers = latus.invokeFlat('@latus/redux/reducers').concat(combineReducers(slices)); const reducers = latus.invokeFlat('@latus/redux/reducers').concat(combineReducers(slices));
const reducer = reduceReducers({}, ...reducers); const reducer = reduceReducers({}, ...reducers);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,13 @@
import D from 'debug';
import proxyaddr from 'proxy-addr'; import proxyaddr from 'proxy-addr';
import SocketIoServer from 'socket.io'; import SocketIoServer from 'socket.io';
import normalize from './normalize';
import ServerSocket from './socket'; import ServerSocket from './socket';
import SocketIoParser from './packet/socket.io-parser'; import SocketIoParser from './packet/socket.io-parser';
const debug = D('@latus/socket/server/sockets');
export default class SocketServer { export default class SocketServer {
constructor(httpServer, latus) { constructor(httpServer, latus) {
@ -56,9 +60,22 @@ export default class SocketServer {
this.latus.invokeSequential('@latus/socket/connect', serverSocket); this.latus.invokeSequential('@latus/socket/connect', serverSocket);
} }
send(packet, channel = '/') { static send(latus, nsp, packetOrDehydrated) {
const packet = normalize(latus, packetOrDehydrated);
debug('sending packet %s(%j)', packet.constructor.type, packet.data);
const {id} = packet.constructor; const {id} = packet.constructor;
this.io.sockets.to(channel).binary(true).emit(id, packet.data); nsp.binary(true).emit(id, packet.data);
}
send(packet) {
return this.constructor.send(this.latus, this.io.sockets, packet);
}
to(room) {
return {
send: (packet) => this.constructor.send(this.latus, this.io.of(room), packet),
};
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff