@signaltree/callable-syntax 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +157 -0
- package/package.json +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
## @signaltree/callable-syntax
|
|
2
|
+
|
|
3
|
+
Zero-runtime callable syntax transform for SignalTree. Enables elegant developer experience that compiles away completely.
|
|
4
|
+
|
|
5
|
+
### What It Does
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
// You write (with great DX):
|
|
9
|
+
tree.$.user.name('Alice');
|
|
10
|
+
tree.$.count((n) => n + 1);
|
|
11
|
+
|
|
12
|
+
// Transform converts to (zero overhead):
|
|
13
|
+
tree.$.user.name.set('Alice');
|
|
14
|
+
tree.$.count.update((n) => n + 1);
|
|
15
|
+
|
|
16
|
+
// Getters work unchanged:
|
|
17
|
+
const name = tree.$.user.name();
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @signaltree/core
|
|
24
|
+
npm install -D @signaltree/callable-syntax
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Key**: Install as dev dependency since it's a build-time tool only.
|
|
28
|
+
|
|
29
|
+
### Setup for Teams
|
|
30
|
+
|
|
31
|
+
#### Angular Projects
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// angular.json - add to build options
|
|
35
|
+
{
|
|
36
|
+
"build": {
|
|
37
|
+
"options": {
|
|
38
|
+
"customWebpackConfig": {
|
|
39
|
+
"path": "./webpack.extra.js"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
// webpack.extra.js
|
|
48
|
+
const { SignalTreeWebpackPlugin } = require('@signaltree/callable-syntax/webpack');
|
|
49
|
+
|
|
50
|
+
module.exports = {
|
|
51
|
+
plugins: [new SignalTreeWebpackPlugin()],
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### Vite Projects
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
// vite.config.ts
|
|
59
|
+
import { defineConfig } from 'vite';
|
|
60
|
+
import { signalTreeSyntaxTransform } from '@signaltree/callable-syntax/vite';
|
|
61
|
+
|
|
62
|
+
export default defineConfig({
|
|
63
|
+
plugins: [signalTreeSyntaxTransform()],
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Webpack
|
|
68
|
+
|
|
69
|
+
````ts
|
|
70
|
+
#### Webpack (Manual Setup)
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
// webpack.config.js
|
|
74
|
+
const { SignalTreeTransform } = require('@signaltree/callable-syntax/transform');
|
|
75
|
+
|
|
76
|
+
module.exports = {
|
|
77
|
+
module: {
|
|
78
|
+
rules: [
|
|
79
|
+
{
|
|
80
|
+
test: /\.tsx?$/,
|
|
81
|
+
use: [
|
|
82
|
+
'ts-loader',
|
|
83
|
+
{
|
|
84
|
+
loader: 'babel-loader',
|
|
85
|
+
options: {
|
|
86
|
+
plugins: [SignalTreeTransform]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
````
|
|
95
|
+
|
|
96
|
+
#### Babel Configuration
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
// .babelrc or babel.config.json
|
|
100
|
+
{
|
|
101
|
+
"plugins": ["@signaltree/callable-syntax/babel-plugin"]
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Development Workflow
|
|
106
|
+
|
|
107
|
+
The transform only affects build output - your TypeScript will still type-check correctly with callable syntax because SignalTree includes the necessary type augmentations.
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { createSignalStore } from '@signaltree/core';
|
|
111
|
+
|
|
112
|
+
const store = createSignalStore({
|
|
113
|
+
todos: [] as Todo[],
|
|
114
|
+
filter: 'all' as 'all' | 'active' | 'completed',
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// TypeScript understands both forms:
|
|
118
|
+
store.$.todos(newTodos); // Callable syntax (transforms away)
|
|
119
|
+
store.$.todos.set(newTodos); // Direct syntax (stays as-is)
|
|
120
|
+
|
|
121
|
+
// Getters always stay the same:
|
|
122
|
+
const currentTodos = store.$.todos();
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Production Build
|
|
126
|
+
|
|
127
|
+
In production builds, only direct Angular signal calls remain - no runtime overhead, no wrapper functions, no Proxy objects. The callable syntax is purely developer experience sugar.
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### TypeScript
|
|
132
|
+
|
|
133
|
+
No per-file imports required in this repo. Types are loaded via root `tsconfig`:
|
|
134
|
+
|
|
135
|
+
- `@signaltree/core` defines callable `NodeAccessor<T>`.
|
|
136
|
+
- Leaves are callable `WritableSignal`s at the type level for consistent DX.
|
|
137
|
+
If you’re consuming externally, include `@signaltree/callable-syntax/augmentation` in your `compilerOptions.types`.
|
|
138
|
+
|
|
139
|
+
### Configuration Options
|
|
140
|
+
|
|
141
|
+
| Option | Description | Default |
|
|
142
|
+
| --------------- | ------------------------------------------- | ----------------------------------------------- | -------- | --------- |
|
|
143
|
+
| include | Files to include (RegExp) | /src/.\*\.(t | j)sx?$/ |
|
|
144
|
+
| exclude | Files to exclude (RegExp) | /node_modules | \.spec\. | \.test\./ |
|
|
145
|
+
| rootIdentifiers | Root variable names containing a SignalTree | ['tree'] (exported as DEFAULT_ROOT_IDENTIFIERS) |
|
|
146
|
+
| debug | Log transformed counts | false |
|
|
147
|
+
|
|
148
|
+
### Notes
|
|
149
|
+
|
|
150
|
+
- Pure dev-time; adds 0 bytes to production bundle.
|
|
151
|
+
- Does not modify runtime; you can mix standard `.set()` / `.update()` calls freely.
|
|
152
|
+
- Safe fallback: if plugin absent, callable writes just become runtime errors you can catch in CI (recommend lint rule if enforcing).
|
|
153
|
+
|
|
154
|
+
### License
|
|
155
|
+
|
|
156
|
+
Business Source License 1.1 (BSL-1.1) – converts to MIT on Change Date per root project license.
|
|
157
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@signaltree/callable-syntax",
|
|
3
|
+
"version": "4.0.3",
|
|
4
|
+
"description": "Optional zero-runtime callable syntax transform for SignalTree unified leaf API.",
|
|
5
|
+
"license": "BSL-1.1",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"main": "./dist/packages/callable-syntax/src/index.js",
|
|
8
|
+
"module": "./dist/packages/callable-syntax/src/index.js",
|
|
9
|
+
"types": "./dist/packages/callable-syntax/src/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/packages/callable-syntax/src/index.d.ts",
|
|
13
|
+
"require": "./dist/packages/callable-syntax/src/index.js",
|
|
14
|
+
"import": "./dist/packages/callable-syntax/src/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./vite": {
|
|
17
|
+
"types": "./dist/packages/callable-syntax/src/lib/vite-plugin.d.ts",
|
|
18
|
+
"require": "./dist/packages/callable-syntax/src/lib/vite-plugin.js",
|
|
19
|
+
"import": "./dist/packages/callable-syntax/src/lib/vite-plugin.js"
|
|
20
|
+
},
|
|
21
|
+
"./webpack": {
|
|
22
|
+
"types": "./dist/packages/callable-syntax/src/lib/webpack-plugin.d.ts",
|
|
23
|
+
"require": "./dist/packages/callable-syntax/src/lib/webpack-plugin.js",
|
|
24
|
+
"import": "./dist/packages/callable-syntax/src/lib/webpack-plugin.js"
|
|
25
|
+
},
|
|
26
|
+
"./augmentation": {
|
|
27
|
+
"types": "./dist/packages/callable-syntax/src/augmentation.d.ts",
|
|
28
|
+
"require": "./dist/packages/callable-syntax/src/augmentation.js",
|
|
29
|
+
"import": "./dist/packages/callable-syntax/src/augmentation.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"tslib": "^2.3.0",
|
|
38
|
+
"@babel/generator": "^7.28.3",
|
|
39
|
+
"@babel/parser": "^7.28.4",
|
|
40
|
+
"@babel/traverse": "^7.28.4",
|
|
41
|
+
"@babel/types": "^7.28.4"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@angular/core": ">=20.0.0",
|
|
45
|
+
"@signaltree/core": ">=4.0.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@angular/core": "~20.3.0",
|
|
49
|
+
"@signaltree/core": "4.0.2",
|
|
50
|
+
"@types/babel__traverse": "^7.20.0",
|
|
51
|
+
"@types/babel__generator": "^7.20.0",
|
|
52
|
+
"@types/node": "^20.0.0",
|
|
53
|
+
"vite": "^5.0.0",
|
|
54
|
+
"webpack": "^5.90.0",
|
|
55
|
+
"@types/webpack": "^5.28.0"
|
|
56
|
+
}
|
|
57
|
+
}
|