Skip to content

Commit

Permalink
chore: call getCode
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasticsoul committed Jan 15, 2024
1 parent e960f0c commit 41d6b7e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions docs/docs/playground/demos/Playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import Console from './Console';
import * as codes from './codes';
import './index.less';

function getCode(name: string, subName: string) {
const codeDict: any = codes;
return codeDict[name]?.[subName] || '';
}

const scope = { helux, React, ...helux };
const subNames: Record<string, string> = {
atom: 'primitive',
Expand All @@ -19,14 +24,10 @@ const cachedSubNames: Record<string, string> = {};
const obj = qs.parse(window.location.search, { ignoreQueryPrefix: true });
const name = obj.n || 'atom';
const subName = obj.s || 'primitive';

function getCode(name: string, subName: string) {
const codeDict: any = codes;
return codeDict[name]?.[subName] || '';
}
const code = getCode(name, subName);

export default () => {
const [info, setInfo] = React.useState({ name, subName, code: getCode('atom', 'primitive'), });
const [info, setInfo] = React.useState({ name, subName, code });
const changeCode = (name: string) => {
const subName = cachedSubNames[name] || subNames[name] || 'primitive';
setInfo({ name, subName, code: getCode(name, subName) });
Expand Down

0 comments on commit 41d6b7e

Please sign in to comment.