Skip to content

Commit

Permalink
improve code scoping (#116)
Browse files Browse the repository at this point in the history
* scope glimmer api

* +
  • Loading branch information
lifeart authored May 1, 2024
1 parent 80ea8b4 commit 5939146
Show file tree
Hide file tree
Showing 29 changed files with 40 additions and 35 deletions.
7 changes: 6 additions & 1 deletion src/components/pages/Benchmark.gts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { buildData, swapRows, updateData, type Item } from '@/utils/data';
import {
buildData,
swapRows,
updateData,
type Item,
} from '@/utils/benchmark/data';
import { Component, tracked, cellFor, type Cell } from '@lifeart/gxt';
import { Header } from './benchmark/Header.gts';
import { Row } from './benchmark/Row.gts';
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'glint-environment-gxt';
import 'decorator-transforms/globals';

import { createBenchmark } from '@/utils/benchmark';
import { createBenchmark } from '@/utils/benchmark/benchmark';
import { router } from '@/services/router';
import {
enforcePaintEvent,
ButtonSelectors,
emitDomClickEvent,
waitForIdle,
} from '@/utils/compat';
} from '@/utils/benchmark/compat';

// @ts-check
// https://codepen.io/lifeart/pen/abMzEZm?editors=0110
Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'decorator-transforms/globals';
import { URL } from 'node:url';
import { router } from '@/services/router';
import { Application } from '@/components/Application.gts';
import { render as renderSSR } from '@/utils/ssr';
import { render as renderSSR } from '@/utils/ssr/ssr';

export async function render(url: string) {
const urlInstance = new URL(url);
Expand Down
4 changes: 2 additions & 2 deletions src/tests/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { type ComponentReturnType, renderComponent } from '@/utils/component';
import { getDocument } from '@/utils/dom-api';
import { withRehydration } from '@/utils/rehydration';
import { withRehydration } from '@/utils/ssr/rehydration';
import { getRoot, resetNodeCounter, setRoot, resetRoot } from '@/utils/dom';
import { renderInBrowser } from '@/utils/ssr';
import { renderInBrowser } from '@/utils/ssr/ssr';
import { runDestructors } from '@/utils/component';

export async function cleanupRender() {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/benchmark.ts → src/utils/benchmark/benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Application } from '@/components/Application.gts';
import { withRehydration } from '@/utils/rehydration';
import { withRehydration } from '@/utils/ssr/rehydration';
import { getDocument } from '@/utils/dom-api';
import { measureRender } from '@/utils/measure-render';
import { measureRender } from '@/utils/benchmark/measure-render';
import { setResolveRender } from '@/utils/runtime';

export function createBenchmark() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/utils/component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DestructorFn, Destructors } from '@/utils/destroyable';
import { DestructorFn, Destructors } from '@/utils/glimmer/destroyable';
import type {
TemplateContext,
Context,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/if.ts → src/utils/control-flow/if.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
deepFnValue,
} from '@/utils/reactive';
import { opcodeFor } from '@/utils/vm';
import { associateDestroyable } from './component';
import { associateDestroyable } from '../component';
import { api } from '@/utils/dom-api';
import {
$DEBUG_REACTIVE_CONTEXTS,
Expand All @@ -21,7 +21,7 @@ import {
isFn,
isPrimitive,
IFS_FOR_HMR,
} from './shared';
} from '../shared';

export function ifCondition(
ctx: Component<any>,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/list.ts → src/utils/control-flow/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {
isPrimitive,
isTagLike,
LISTS_FOR_HMR,
} from './shared';
import { isRehydrationScheduled } from './rehydration';
} from '../shared';
import { isRehydrationScheduled } from '../ssr/rehydration';

export function getFirstNode(
rawItem:
Expand Down
8 changes: 4 additions & 4 deletions src/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import { checkOpcode, opcodeFor } from '@/utils/vm';
import {
SyncListComponent,
AsyncListComponent,
} from '@/utils/list';
import { ifCondition } from '@/utils/if';
} from '@/utils/control-flow/list';
import { ifCondition } from '@/utils/control-flow/if';
import {
DestructorFn,
Destructors,
destroy,
registerDestructor,
} from './destroyable';
} from './glimmer/destroyable';
import { api } from '@/utils/dom-api';
import {
isFn,
Expand All @@ -43,7 +43,7 @@ import {
IN_SSR_ENV,
COMPONENTS_HMR,
} from './shared';
import { isRehydrationScheduled } from './rehydration';
import { isRehydrationScheduled } from './ssr/rehydration';
import { createHotReload } from './hmr';

// EMPTY DOM PROPS
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Cell, formula } from '@lifeart/gxt';
import { opcodeFor, evaluateOpcode } from './vm';
import { opcodeFor, evaluateOpcode } from '../vm';

interface Cache {
tag: ReturnType<typeof formula>;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
isRendering,
setIsRendering,
cell,
} from './reactive';
} from '../reactive';

export { cellFor as tagFor } from '@lifeart/gxt';

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cell, type Cell } from '@lifeart/gxt';
import { isFn } from './shared';
import { isFn } from '../shared';
interface Storage<T> {
cell: Cell<T>;
update(value: T): void;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/hmr.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getFirstNode } from '@/utils/list';
import { getFirstNode } from '@/utils/control-flow/list';
import { COMPONENTS_HMR, IFS_FOR_HMR, LISTS_FOR_HMR } from './shared';
import {
renderElement,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export {
Component,
type ComponentReturnType,
} from '@/utils/component';
export { registerDestructor } from '@/utils/destroyable';
export { registerDestructor } from '@/utils/glimmer/destroyable';
export { hbs, scope } from '@/utils/template';
export { effect } from '@/utils/vm';
export * from '@/utils/dom';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as backburner from 'backburner.js';
import { getRoot } from './dom';
import { $_debug_args, RENDER_TREE, getBounds } from './shared';
import { Component } from '.';
import { Cell, MergedCell, getCells, getMergedCells } from './reactive';
import { $args } from './shared';
import { getRoot } from '../dom';
import { $_debug_args, RENDER_TREE, getBounds } from '../shared';
import { Component } from '..';
import { Cell, MergedCell, getCells, getMergedCells } from '../reactive';
import { $args } from '../shared';
import { inspect } from '@/utils/inspector';

const genericProxy = new Proxy(
Expand Down
2 changes: 1 addition & 1 deletion src/utils/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
executeTag,
relatedTags,
} from '@/utils/reactive';
import { isRehydrationScheduled } from './rehydration';
import { isRehydrationScheduled } from './ssr/rehydration';

let revalidateScheduled = false;
type voidFn = () => void;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type ComponentReturnType,
} from '@/utils/component';
import { type AnyCell } from './reactive';
import { type BasicListComponent } from './list';
import { type BasicListComponent } from './control-flow/list';

export const isTag = Symbol('isTag');
export const $template = 'template' as const;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/utils/rehydration.ts → src/utils/ssr/rehydration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type ComponentReturnType } from '@/utils/component';
import { getNodeCounter, resetNodeCounter } from '@/utils/dom';
import { api as rehydrationDomApi } from '@/utils/rehydration-dom-api';
import { api as rehydrationDomApi } from '@/utils/ssr/rehydration-dom-api';
import { api as domApi } from '@/utils/dom-api';
const withRehydrationStack: HTMLElement[] = [];
const commentsToRehydrate: Comment[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ssr.ts → src/utils/ssr/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
runDestructors,
type ComponentReturnType,
} from '@/utils/component';
import { setDocument, getDocument } from './dom-api';
import { setDocument, getDocument } from '../dom-api';
import { getRoot, resetNodeCounter, resetRoot } from '@/utils/dom';

type EnvironmentParams = {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@/utils/*": ["./src/utils/*"],
"@/services/*": ["./src/services/*"],
"@lifeart/gxt/test-utils": ["./src/tests/utils"],
"@lifeart/gxt/ember-inspector": ["./src/utils/ember-inspector"],
"@lifeart/gxt/ember-inspector": ["./src/utils/inspector/ember-inspector"],
"@lifeart/gxt": ["./src/utils/index"]
},
"types": ["vite/client", "./types"]
Expand Down
6 changes: 3 additions & 3 deletions vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export default defineConfig(({ mode }) => ({
entry: [
path.join(currentPath, "src", "utils", "index.ts"),
path.join(currentPath, "plugins", "compiler.ts"),
path.join(currentPath, "src", "utils", "ember-inspector.ts"),
path.join(currentPath, "src", "utils", "glimmer-compat.ts"),
path.join(currentPath, "src", "utils", "inspector", "ember-inspector.ts"),
path.join(currentPath, "src", "utils", "glimmer", "glimmer-compat.ts"),
path.join(currentPath, "src", "tests", "utils.ts"),
],
name: "gxt",
Expand Down Expand Up @@ -161,7 +161,7 @@ export default defineConfig(({ mode }) => ({
"@lifeart/gxt/ember-inspector": path.join(
currentPath,
"src",
"utils",
"utils","inspector",
"ember-inspector.ts",
),
"@lifeart/gxt/test-utils": path.join(
Expand Down

0 comments on commit 5939146

Please sign in to comment.