Skip to content

Commit 5544b9b

Browse files
committed
More tweaks
1 parent 344faef commit 5544b9b

File tree

19 files changed

+199
-314
lines changed

19 files changed

+199
-314
lines changed

CONVENTIONS.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ This document defines the consistent patterns and conventions used across all Ti
4141
### React Components
4242

4343
```typescript
44-
// Define component
45-
const App = () => {
44+
// Define and export component
45+
export const App = () => {
4646
return (
4747
<StrictMode>
4848
<Provider>
@@ -51,9 +51,6 @@ const App = () => {
5151
</StrictMode>
5252
);
5353
};
54-
55-
// Export at end of file
56-
export {App};
5754
```
5855

5956
### Vanilla Functions
@@ -82,7 +79,7 @@ export /* re-export hooks */ {};
8279

8380
export const Store = () => {
8481
const store = useCreateStore(() =>
85-
createMergeableStore(STORE_ID).setTable('todos', {
82+
createMergeableStore().setTable('todos', {
8683
/* ... */
8784
}),
8885
);
@@ -114,7 +111,7 @@ const STORE_ID = 'chat'; // or 'canvas'
114111

115112
export const ChatStore = () => {
116113
const store = useCreateStore(() =>
117-
createMergeableStore(STORE_ID).setTable('messages', {}),
114+
createMergeableStore().setTable('messages', {}),
118115
);
119116

120117
useProvideStore(STORE_ID, store);
@@ -132,7 +129,7 @@ import {createMergeableStore} from 'tinybase';
132129

133130
const STORE_ID = 'todos'; // or 'game'
134131

135-
export const store = createMergeableStore(STORE_ID).setTable('todos', {
132+
export const store = createMergeableStore().setTable('todos', {
136133
/* ... */
137134
});
138135

@@ -152,10 +149,7 @@ export type SettingsStore = typeof settingsStore;
152149
// chatStore.ts or canvasStore.ts
153150
const STORE_ID = 'chat'; // or 'canvas'
154151

155-
export const chatStore = createMergeableStore(STORE_ID).setTable(
156-
'messages',
157-
{},
158-
);
152+
export const chatStore = createMergeableStore().setTable('messages', {});
159153

160154
export type ChatStore = typeof chatStore; // or CanvasStore
161155
```
@@ -284,7 +278,7 @@ Both React and vanilla support schema typing via conditionals:
284278
import {createMergeableStore} from 'tinybase';
285279
{{/if}}
286280

287-
export const store = createMergeableStore(STORE_ID){{#if schemas}}
281+
export const store = createMergeableStore(){{#if schemas}}
288282
.setTablesSchema(SCHEMA){{/if}};
289283
```
290284

screenshots/chat.png

266 Bytes
Loading

screenshots/drawing.png

-1 Bytes
Loading

screenshots/todos.png

-110 Bytes
Loading

src/cli.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,8 @@ const config = {
182182
processIncludedFile: (file: FileConfig, context: TemplateContext) => {
183183
const {javascript} = context;
184184

185-
// Apply smart defaults based on file extension
186185
const prettier =
187186
file.prettier ?? /\.(js|jsx|ts|tsx|css|json|html|md)$/.test(file.output);
188-
// Transpile if the template is TypeScript but we're generating JavaScript
189187
const transpile =
190188
file.transpile ??
191189
(/\.(ts|tsx)\.hbs$/.test(file.template) && javascript === true);

templates/client/src/chat/App.tsx.hbs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
{{includeFile template="client/src/chat/MessageInput.tsx.hbs" output="client/src/MessageInput.{{ext}}"}}
2323
{{addImport "import {MessageInput} from './MessageInput';"}}
2424

25-
const App = () => {
25+
export const App = () => {
2626
return (
2727
<StrictMode>
2828
<Provider>
@@ -35,6 +35,4 @@ return (
3535
</Provider>
3636
</StrictMode>
3737
);
38-
};
39-
40-
export {App};
38+
};

templates/client/src/chat/app.ts.hbs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
{{includeFile template="client/src/chat/messageInput.ts.hbs" output="client/src/messageInput.{{ext}}"}}
2323
{{addImport "import {createMessageInput} from './messageInput';"}}
2424

25-
const app = () => {
25+
export const app = () => {
2626
const appContainer = document.getElementById('app')!;
2727

2828
appContainer.appendChild(createUsernameInput(settingsStore, chatStore));
@@ -31,9 +31,6 @@ appContainer.appendChild(createMessages(chatStore));
3131
const messageInputContainer = createMessageInput(settingsStore, chatStore);
3232
appContainer.appendChild(messageInputContainer);
3333

34-
// Focus the input after it's in the DOM
3534
const messageInput = messageInputContainer.querySelector('input')!;
3635
messageInput.focus();
37-
};
38-
39-
export {app};
36+
};

templates/client/src/chat/messages.ts.hbs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ messagesContainer.appendChild(messageElement);
2323
});
2424
};
2525

26-
// Initial render
2726
updateMessages();
2827

29-
// Listen for changes
3028
store.addTablesListener(updateMessages);
3129

3230
return messagesContainer;

templates/client/src/drawing/App.tsx.hbs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
{{includeFile template="client/src/drawing/Canvas.tsx.hbs" output="client/src/Canvas.{{ext}}"}}
2020
{{addImport "import {Canvas} from './Canvas';"}}
2121

22-
const App = () => {
22+
export const App = () => {
2323
return (
2424
<StrictMode>
2525
<Provider>
@@ -31,6 +31,4 @@ return (
3131
</Provider>
3232
</StrictMode>
3333
);
34-
};
35-
36-
export {App};
34+
};

templates/client/src/drawing/app.ts.hbs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
{{includeFile template="client/src/drawing/canvas.ts.hbs" output="client/src/canvas.{{ext}}"}}
1111
{{addImport "import {createCanvas} from './canvas';"}}
1212

13-
const app = () => {
13+
export const app = () => {
1414
const appContainer = document.getElementById('app')!;
1515

1616
appContainer.appendChild(createDrawingControls(settingsStore, canvasStore));
1717
appContainer.appendChild(createCanvas(settingsStore, canvasStore));
18-
};
19-
20-
export {app};
18+
};

0 commit comments

Comments
 (0)