kopular 1.1.1 → 1.1.2

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.
Files changed (2) hide show
  1. package/GUIDE.md +37 -4
  2. package/package.json +1 -1
package/GUIDE.md CHANGED
@@ -43,6 +43,18 @@ both scripts). `ks check src/app.ks` type-checks without building, if you just w
43
43
  `.Slice(a, b)/.Concat(ys)/.Join(sep)/.Reduce(fn, initial)`.
44
44
  - `x == null` / `x != null` also match `undefined` — a missed `Array.Find`, an absent
45
45
  optional field, etc. all read as `null`.
46
+ - **No `.Match()`/`.Test()`/`.Exec()` on `string` — there is no direct regex-execute method
47
+ at all.** A regex literal (`r"^[a-z]+$"`) only means something as a `match` *pattern*.
48
+ The idiomatic way to classify or extract by character class is `.Split("")` (splits into
49
+ a `string[]` of single characters) plus `match` per character:
50
+ ```ks
51
+ bool isLetter = match c { r"^[a-z]$" => true, _ => false };
52
+ ```
53
+ Build up runs (words, tokens, ...) by iterating those characters and appending to an
54
+ accumulator string, flushing it whenever a non-matching character (or the end) is
55
+ reached — this covers tokenizing/extracting by character class without ever needing a
56
+ hand-written JS shim. Reach for a real shim (below) only for something a `match` pattern
57
+ genuinely can't express, like capturing a submatch.
46
58
  - No object-literal syntax anywhere (`{ key: value }` doesn't exist as a value). A JS API
47
59
  that needs one (rare — `fetch`'s options, `addEventListener`'s options object) needs a
48
60
  small hand-written `.js` shim; Kopular's own `Http`/`FormField` cover the common cases so
@@ -68,10 +80,31 @@ need one: `this.SomeService.Count.Subscribe((v) => this.Update());` in the const
68
80
 
69
81
  **Template bindings**: `{{ expr }}` text, `[prop]="expr"` (real fields for
70
82
  `id`/`className`/`value`/`disabled`/`checked`; anything else is a plain attribute),
71
- `(click)`/`(input)`/`(blur)`/`(change)` events, `[(value)]="Field"` two-way binding
72
- (`Field` can be a bare name, `this.Field`, or a path like `Qty.Value` — not a method call),
73
- `*if="expr"`, `*for="Type v of expr"` (element type required, no inference), `*mount="expr"`
74
- (embeds a live child component, composes with `*for`).
83
+ `(click)`/`(input)`/`(blur)`/`(change)` events, `*if="expr"`, `*for="Type v of expr"`
84
+ (element type required, no inference), `*mount="expr"` (embeds a live child component,
85
+ composes with `*for`).
86
+
87
+ **Two-way binding, `[(value)]="Field"`** — `Field` can be a bare name, `this.Field`, or a
88
+ member path; it's assigned back directly (`Field = e.target.value`), so it must resolve
89
+ to something assignable, never a method call. **A `state<T>` field needs `.Value` on the
90
+ end** — `[(value)]="Qty.Value"`, not `[(value)]="Qty"` (a bare `state<T>` isn't itself a
91
+ `string`, so binding it directly is a type error):
92
+ ```ks
93
+ public state<string> Qty;
94
+ constructor() : base() { this.Qty = state("1"); }
95
+ ```
96
+ ```html
97
+ <input [(value)]="Qty.Value" />
98
+ ```
99
+
100
+ **Exactly one top-level element per template — no auto-wrapping, a hard compile error
101
+ otherwise.** Wrap multiple top-level pieces in one real container element:
102
+ ```html
103
+ <div>
104
+ <input id="text" [(value)]="Draft" />
105
+ <button (click)="Submit()">Go</button>
106
+ </div>
107
+ ```
75
108
 
76
109
  **Hand-written `Render()`** (needed when logic is too dynamic for a template, or a template
77
110
  would obscure more than it clarifies):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kopular",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Kopular: a small component framework for KopScript — components, reactive state, constructor-injected services, routing, real compiled templates, and HTTP, with no DI container",
5
5
  "type": "module",
6
6
  "license": "MIT",