Skip to content

Commit 367a262

Browse files
committed
Apply code review feedback
1 parent 6e1ea0e commit 367a262

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

packages/base/code-ref.gts

+12-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ import {
1616
import { ResolvedCodeRef } from '@cardstack/runtime-common';
1717
import CodeIcon from '@cardstack/boxel-icons/code';
1818

19+
function moduleIsUrlLike(module: string) {
20+
return (
21+
module.startsWith('http') ||
22+
module.startsWith('.') ||
23+
module.startsWith('/')
24+
);
25+
}
26+
1927
class BaseView extends Component<typeof CodeRefField> {
2028
<template>
2129
<div data-test-ref>
@@ -37,11 +45,11 @@ export default class CodeRefField extends FieldDef {
3745
_visited?: Set<string>,
3846
opts?: SerializeOpts,
3947
) {
40-
const moduleIsUrlLike =
41-
codeRef.module.startsWith('http') || codeRef.module.startsWith('.');
4248
return {
4349
...codeRef,
44-
...(opts?.maybeRelativeURL && !opts?.useAbsoluteURL && moduleIsUrlLike
50+
...(opts?.maybeRelativeURL &&
51+
!opts?.useAbsoluteURL &&
52+
moduleIsUrlLike(codeRef.module)
4553
? { module: opts.maybeRelativeURL(codeRef.module) }
4654
: {}),
4755
};
@@ -72,9 +80,7 @@ function maybeSerializeCodeRef(
7280
stack: CardDef[] = [],
7381
) {
7482
if (codeRef) {
75-
const moduleIsUrlLike =
76-
codeRef.module.startsWith('http') || codeRef.module.startsWith('.');
77-
if (moduleIsUrlLike) {
83+
if (moduleIsUrlLike(codeRef.module)) {
7884
// if a stack is passed in, use the containing card to resolve relative references
7985
let moduleHref =
8086
stack.length > 0

packages/base/skill-card.gts

+4-13
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,13 @@ import CodeRefField from './code-ref';
1111
import MarkdownField from './markdown';
1212
import StringField from './string';
1313
import RobotIcon from '@cardstack/boxel-icons/robot';
14-
15-
function djb2_xor(str: string) {
16-
let len = str.length;
17-
let h = 5381;
18-
19-
for (let i = 0; i < len; i++) {
20-
h = (h * 33) ^ str.charCodeAt(i);
21-
}
22-
return (h >>> 0).toString(16);
23-
}
14+
import { simpleHash } from '@cardstack/runtime-common';
2415

2516
function friendlyModuleName(fullModuleUrl: string) {
2617
return fullModuleUrl
2718
.split('/')
28-
.slice(-1)[0]
29-
.replace(/\.gts$/, ' ');
19+
.pop()!
20+
.replace(/\.gts$/, '');
3021
}
3122

3223
export class CommandField extends FieldDef {
@@ -46,7 +37,7 @@ export class CommandField extends FieldDef {
4637
return '';
4738
}
4839

49-
const hashed = djb2_xor(`${this.codeRef.module}#${this.codeRef.name}`);
40+
const hashed = simpleHash(`${this.codeRef.module}#${this.codeRef.name}`);
5041
let name =
5142
this.codeRef.name === 'default'
5243
? friendlyModuleName(this.codeRef.module)

0 commit comments

Comments
 (0)