Skip to content

Commit

Permalink
chore(code-organization): re-organized code
Browse files Browse the repository at this point in the history
GitOrigin-RevId: fcaf9fc0d925b9a11e2347b5ce295fd4bfb92b67
  • Loading branch information
Asim authored and actions-user committed Nov 14, 2024
1 parent e8d82d1 commit fe5d56f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,7 @@ const LeftGeneralTokensPanel = observer(function LeftGeneralTokensPanel() {
);

const [isTargeting, setIsTargeting] = React.useState(false);
const viewCtx = studioCtx?.focusedViewCtx();
const resolver = React.useCallback(useClientTokenResolver(), [
viewCtx?.isFirstRenderComplete,
]);
const resolver = useClientTokenResolver();

const getTokenValue = React.useCallback(
(token: StyleToken) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
makeTokenResolver,
} from "@/wab/shared/cached-selectors";
import { StyleToken } from "@/wab/shared/model/classes";
import * as React from "react";

const RE_VARIABLE_REF = /var\((--[^)]+)\)/;

Expand All @@ -29,7 +30,10 @@ const RE_VARIABLE_REF = /var\((--[^)]+)\)/;
export function useClientTokenResolver(): TokenValueResolver {
const sc = useStudioCtx();
const vc = sc.focusedViewCtx();
const resolver = makeTokenResolver(sc.site);

const resolver = React.useCallback(makeTokenResolver(sc.site), [
vc?.isFirstRenderComplete,
]);
return makeClientTokenResolver(resolver, vc ?? sc);
}

Expand Down
10 changes: 9 additions & 1 deletion platform/wab/src/wab/client/cseval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ export abstract class BaseCliSvrEvaluator {
private _postEvalTasks: (() => any)[] = [];
private _contextFactory: ContextFactory;
private _renderState: RenderState;
private _isFirstRenderComplete = observable.box(false);

get isFirstRenderComplete() {
return this._isFirstRenderComplete.get();
}
set isFirstRenderComplete(v) {
this._isFirstRenderComplete.set(v);
}

constructor({ viewCtx }: { viewCtx: ViewCtx }) {
this._viewCtx = viewCtx;
Expand Down Expand Up @@ -164,7 +172,7 @@ export abstract class BaseCliSvrEvaluator {
this.rootNode = this.renderRoot();
viewCtx.canvasCtx.rerender(this.rootNode, viewCtx);
this.addPostEval(() => {
viewCtx.isFirstRenderComplete = true;
this.isFirstRenderComplete = true;
});
}
}
Expand Down
12 changes: 4 additions & 8 deletions platform/wab/src/wab/client/studio-ctx/view-ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ export class ViewCtx extends WithDbCtx {

csEvaluator: DevCliSvrEvaluator;

get isFirstRenderComplete() {
return this.csEvaluator.isFirstRenderComplete;
}

private disposals: (() => void)[] = [];
private _isDisposed = false;

Expand All @@ -182,14 +186,6 @@ export class ViewCtx extends WithDbCtx {
return this._nextFocusedTpl;
}

private _isFirstRenderComplete = observable.box(false);
get isFirstRenderComplete() {
return this._isFirstRenderComplete.get();
}
set isFirstRenderComplete(v) {
this._isFirstRenderComplete.set(v);
}

private _highlightParam = observable.box<
| {
param: Param;
Expand Down

0 comments on commit fe5d56f

Please sign in to comment.