Skip to content

Commit

Permalink
refactor(web)!: pass container to @flecks/web/client.up
Browse files Browse the repository at this point in the history
Fixes: #9
  • Loading branch information
cha0s committed Feb 8, 2024
1 parent 9a0a028 commit 1083b41
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
4 changes: 1 addition & 3 deletions packages/react/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ const debug = D('@flecks/react/client');
export {FlecksContext};

export const hooks = {
'@flecks/web/client.up': async (flecks) => {
'@flecks/web/client.up': async (container, flecks) => {
const {ssr} = flecks.get('@flecks/react');
const {appMountId} = flecks.get('@flecks/web');
const container = window.document.getElementById(appMountId);
debug('%sing...', ssr ? 'hydrat' : 'render');
const RootComponent = React.createElement(
React.StrictMode,
Expand Down
2 changes: 1 addition & 1 deletion packages/redux/src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import localStorageEnhancer from './local-storage';

export const hooks = {
'@flecks/web/client.up': Flecks.priority(
async (flecks) => {
async (container, flecks) => {
const slices = await flecks.invokeMergeUniqueAsync('@flecks/redux.slices');
const reducer = await createReducer(flecks, slices);
// Hydrate from server.
Expand Down
2 changes: 1 addition & 1 deletion packages/socket/src/client/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SocketClient from './socket';

export const hooks = {
'@flecks/web/client.up': async (flecks) => {
'@flecks/web/client.up': async (container, flecks) => {
const socket = new SocketClient(flecks);
flecks.socket.client = socket;
await socket.connect();
Expand Down
5 changes: 4 additions & 1 deletion packages/web/build/flecks.hooks.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
export const hooks = {
/**
* Define sequential actions to run when the client comes up.
*
* @param {Element} container The root DOM element of the application.
*
* @invoke SequentialAsync
*/
'@flecks/web/client.up': async () => {
'@flecks/web/client.up': async (container) => {
await youCanDoAsyncThingsHere();
},
/**
Expand Down
6 changes: 4 additions & 2 deletions packages/web/src/server/build/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ const {version} = require('@flecks/web/package.json');
try {
const flecks = await Flecks.from(runtime);
window.flecks = flecks;
await flecks.invokeSequentialAsync('@flecks/web/client.up');
const appMountContainerId = `#${config['@flecks/web'].appMountId}-container`;
const containerId = `#${config['@flecks/web'].appMountId}`;
const container = window.document.querySelector(containerId);
await flecks.invokeSequentialAsync('@flecks/web/client.up', container);
const appMountContainerId = `${containerId}-container`;
window.document.querySelector(appMountContainerId).style.display = 'block';
debug('up!');
}
Expand Down

0 comments on commit 1083b41

Please sign in to comment.