Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove shims #136

Merged
merged 4 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 0 additions & 68 deletions packages/compiler/src/component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
type ComponentStateMap = Map<string, { [key: string | symbol]: any }>;

/**
* Returns the name to be used for the Component function
* @param componentPath
Expand Down Expand Up @@ -29,13 +27,6 @@ export function buildComponentFunction({
if (isRoot) {
return `
function ${functionName}() {
const { state, State } = (
${initializeComponentState.toString()}
)({
ComponentState,
componentInstanceId: props?.__bweMeta?.componentId,
renderComponent,
});
${componentSource}
}
`;
Expand All @@ -46,66 +37,7 @@ export function buildComponentFunction({
function ${functionName}(__bweInlineComponentProps) {
const { __bweMeta, props: __componentProps } = __bweInlineComponentProps;
const props = Object.assign({ __bweMeta }, __componentProps);
const { state, State } = (
${initializeComponentState.toString()}
)({
ComponentState,
componentInstanceId: [
'${componentPath}',
__bweInlineComponentProps.id,
__bweMeta?.parentMeta?.componentId,
].filter((c) => c !== undefined).join('##'),
renderComponent,
});
${componentSource}
}
`;
}

interface InitializeComponentStateParams {
ComponentState: ComponentStateMap;
componentInstanceId: string;
renderComponent?: ({ stateUpdate }: { stateUpdate: string }) => void;
}

function initializeComponentState({
ComponentState,
componentInstanceId,
renderComponent,
}: InitializeComponentStateParams) {
const state = new Proxy(
{},
{
get(_, key) {
try {
return ComponentState.get(componentInstanceId)?.[key];
} catch {
return undefined;
}
},
}
);
const State = {
init(obj: any) {
if (!ComponentState.has(componentInstanceId)) {
ComponentState.set(componentInstanceId, obj);
}
},
update(newState: any, initialState = {}) {
ComponentState.set(
componentInstanceId,
Object.assign(
initialState,
ComponentState.get(componentInstanceId),
newState
)
);
renderComponent?.({ stateUpdate: JSON.stringify(newState) });
},
};

return {
state,
State,
};
}
232 changes: 0 additions & 232 deletions packages/container/src/api.ts

This file was deleted.

Loading
Loading