refactor: sharing using some very tricksy tricks

This commit is contained in:
cha0s 2021-01-25 22:15:22 -06:00
parent 88391fa174
commit 419278e90e
5 changed files with 7 additions and 11 deletions

View File

@ -9,6 +9,7 @@
"clean": "rm -rf yarn.lock node_modules $(node -e \"process.stdout.write(require('./package.json').files.filter((file) => {const parts = file.split('/'); return 1 === parts.length || 'test' !== parts[0];}).join(' '));\") && yarn",
"forcepub": "npm unpublish --force $(node -e 'const {name, version} = require(`./package.json`); process.stdout.write(`${name}@${version}`)') && npm publish",
"lint": "NODE_PATH=./node_modules eslint --format codeframe --ext mjs,js .",
"postinstall": "mkdir -p node_modules/@latus/react && ln -fs ../../../src/client.js node_modules/@latus/react",
"test": "yarn --silent run build --display none && mocha --colors test.js"
},
"files": [

View File

@ -3,10 +3,7 @@ import {render} from 'react-dom';
import LatusContext from './context';
export {default as React} from 'react';
export * from 'react';
export {default as LatusContext} from './context';
export {default as useLatus} from './hooks/use-latus';
export default {
hooks: {

View File

@ -1,5 +1,6 @@
import {useContext} from 'react';
import LatusContext from '../context';
// eslint-disable-next-line import/no-extraneous-dependencies
import {LatusContext} from '@latus/react/client';
export default () => useContext(LatusContext);

View File

@ -1,8 +1,9 @@
export {default as React} from 'react';
export * from 'react';
export {default as ReactDom} from 'react-dom';
export {default as PropTypes} from 'prop-types';
export * from 'react';
export {default as useLatus} from './hooks/use-latus';
export default {
hooks: {

View File

@ -1,11 +1,7 @@
import {useContext} from '@latus/react';
import {LatusContext} from '@latus/react/client';
import {useLatus} from '@latus/react';
export default function useSocket() {
const latus = useContext(LatusContext);
if (!latus) {
throw new Error('useSocket: no latus context');
}
const latus = useLatus();
const sock = latus.get('%socket');
if (!sock) {
throw new Error('useSocket: no configured socket');