Skip to content

Commit

Permalink
props.alem.rootProps now causes re-render
Browse files Browse the repository at this point in the history
  • Loading branch information
wpdas committed Apr 10, 2024
1 parent 5cd06a3 commit 2de6c81
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 33 deletions.
2 changes: 1 addition & 1 deletion lib/alem-vm/components/AppIndexer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ const AlemApp = useMemo(() => {
/>
</AlemTheme>
);
}, [props.alem.ready, props.alem.alemExternalStylesBody]);
}, [props.alem.ready, props.alem.alemExternalStylesBody, props.alem.rootProps]);

return AlemApp;
18 changes: 0 additions & 18 deletions lib/alem-vm/importable/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,6 @@ const Router = (props: RouterProps) => {
const { routeParameterName, routeType, activeRoute } = alemRoutes;
const routeParamName = parameterName || routeParameterName;

// Registra como listener das props do root
useEffect(() => {
const handler = (data: any) => {
const _type = type || "URLBased";
if (_type === "URLBased") {
alemRoutes.updateRouteParameters({
activeRoute: data[routeParamName],
});
}
};

alem.registerListenerHandler(handler);

return () => {
alem.unregisterListenerHandler();
};
}, []);

const checkIfPathIsIncludedToRoutes = (routePath: string) => {
let pathFound = false;
if (routes) {
Expand Down
38 changes: 24 additions & 14 deletions lib/alem-vm/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
* Todos os items do state inicial
*/

import { Route, State, Storage, asyncFetch, state } from "./alem-vm";
import {
Route,
State,
Storage,
asyncFetch,
state,
useEffect,
useState,
} from "./alem-vm";

/**
* Update the alem state
Expand All @@ -25,18 +33,20 @@ const alemState = () => state.alem as typeof AlemStateInitialBody.alem;

const AlemStateInitialBody = {
alem: {
// System to send root properties to listeners
rootPropsListeners: [],
registerListenerHandler: (handler: (data: any) => void) => {
if (!props.alem.rootPropsListeners.includes(handler)) {
props.alem.rootPropsListeners.push(handler);
}
},
unregisterListenerHandler: (handler: (data: any) => void) => {
props.alem.rootPropsListeners = props.alem.rootPropsListeners.filter(
(item) => item !== handler,
);
},
// === System to send root properties to listeners ===
// INFO: Desativado pois as props sao repassadas quando
// elas sao mudadas no root (aqui)
// rootPropsListeners: [],
// registerListenerHandler: (handler: (data: any) => void) => {
// if (!props.alem.rootPropsListeners.includes(handler)) {
// props.alem.rootPropsListeners.push(handler);
// }
// },
// unregisterListenerHandler: (handler: (data: any) => void) => {
// props.alem.rootPropsListeners = props.alem.rootPropsListeners.filter(
// (item) => item !== handler,
// );
// },

ready: false,
/**
Expand Down Expand Up @@ -227,7 +237,7 @@ if (props.alem.keepRoute) {

// Chama todos os metodos guardados no alem.handlers quando a propriedade
// do root mudar
props.alem.rootPropsListeners.forEach((handler) => handler(props));
// props.alem.rootPropsListeners.forEach((handler) => handler(props));

export type Alem = any;

Expand Down

0 comments on commit 2de6c81

Please sign in to comment.