Skip to content

Commit 2c87c78

Browse files
committed
minor improvements
Various modules now use `reqFun` rather than `reqCls` to verify that inputs are "classes". This may produce false positives for arrow functions, but those would quickly fail on any `new` attempt anyway, just with a different message. This allows better compatibility with "old"-style "classes" defined via the `function` keyword, which may be outside of user control for transpilation or polyfill reasons. `lang.mjs`: `reset` now returns the same value which was provided as an input. Added `swap`. `obj.mjs`: `assign` and `patch` are now variadic, similar to `Object.assign`.
1 parent 4167c1f commit 2c87c78

38 files changed

+585
-545
lines changed

doc/lang/isCls.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
True if the input is a function with a prototype, likely to be a class. False for arrow functions such as `() => {}`, which don't have a prototype.
1+
True if the input is a function with a prototype, suitable for `instanceof` checks. False for arrow functions such as `() => {}`, which don't have a prototype.

doc/prax_readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ For SSR (server-side rendering), Prax needs our lightweight DOM shim:
154154
import * as p from '{{featUrl prax}}'
155155
import * as dg from '{{featUrl dom_global_shim}}'
156156

157-
const ren = new p.Ren(dg.global)
157+
const ren = new p.Ren({env: dg.global})
158158
const {E} = ren
159159

160160
const elem = E(`div`, {
@@ -170,16 +170,16 @@ console.log(elem.outerHTML)
170170
*/
171171
```
172172

173-
For SSR/SPA hybrids, configure an [importmap](https://wicg.github.io/import-maps/) or [bundler](https://esbuild.github.io) to choose the right global `document` and pass it to `Ren`. The rest will just work.
173+
For SSR/SPA hybrids, configure an [importmap](https://wicg.github.io/import-maps/) or [bundler](https://esbuild.github.io) to choose the right global "environment" and pass it to `Ren`. The rest will just work.
174174

175175
```js
176176
import * as p from '{{featUrl prax}}'
177177

178-
// Your bundler or importmap should choose the right one.
178+
// Your bundler or importmap needs to choose the right one.
179179
import * as dg from '{{featUrl dom_global_shim}}'
180180
import * as dg from '{{featUrl dom_global_native}}'
181181

182-
const ren = new p.Ren(dg.global)
182+
const ren = new p.Ren({env: dg.global})
183183
const {E} = ren
184184

185185
// In both environments, this will be a DOM element.
@@ -197,7 +197,7 @@ Rendering a complete document with doctype:
197197
import * as p from '{{featUrl prax}}'
198198
import * as dg from '{{featUrl dom_global_shim}}'
199199

200-
const ren = new p.Ren(dg.global)
200+
const ren = new p.Ren({env: dg.global})
201201
const {E} = ren
202202

203203
const elem = E(`html`, {

docs/cli_readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
CLI args:
2424

2525
```js
26-
import * as cl from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/cli.mjs'
26+
import * as cl from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/cli.mjs'
2727

2828
const cli = cl.Flag.os()
2929

@@ -34,15 +34,15 @@ console.log(...cli.args)
3434
Console clearing:
3535

3636
```js
37-
import * as cl from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/cli.mjs'
37+
import * as cl from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/cli.mjs'
3838

3939
cl.emptty()
4040
```
4141

4242
Clearing the console only once, before running your code:
4343

4444
```js
45-
import 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/cli_emptty.mjs'
45+
import 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/cli_emptty.mjs'
4646
```
4747

4848
## API

docs/coll_readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Port and rework of https://github.com/mitranim/jol.
2626
## Usage
2727

2828
```js
29-
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/coll.mjs'
29+
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/coll.mjs'
3030
```
3131

3232
## API
@@ -101,8 +101,8 @@ Links: [source](../coll.mjs#L100); [test/example](../test/coll_test.mjs#L218).
101101
Variant of [#`Bmap`](#class-bmap) with support for key and value checks. Subclasses must override methods `.reqKey` and `.reqVal`. These methods are automatically called by `.set`. Method `.reqKey` must validate and return the given key, and method `.reqVal` must validate and return the given value. Use type assertions provided by [`lang`](lang_readme.md).
102102

103103
```js
104-
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/lang.mjs'
105-
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/coll.mjs'
104+
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/lang.mjs'
105+
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/coll.mjs'
106106

107107
class StrNatMap extends c.TypedMap {
108108
reqKey(key) {return l.reqStr(key)}
@@ -242,7 +242,7 @@ Differences and advantages over `Array`:
242242
The overhead of the wrapper is insignificant.
243243

244244
```js
245-
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/coll.mjs'
245+
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/coll.mjs'
246246

247247
console.log(new c.Vec())
248248
// Vec{Symbol(val): []}

docs/dom_global_native_readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ In code intended only for browsers, simply use DOM globals. In code intended onl
1515
```js
1616
/*
1717
Use a bundler or importmap to alias this import to one of:
18-
https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/dom_global_native.mjs
19-
https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/dom_global_shim.mjs
18+
https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/dom_global_native.mjs
19+
https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/dom_global_shim.mjs
2020
*/
2121
import * as dg from 'dom_global'
2222

docs/dom_global_shim_readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ In code intended only for non-browser environments, simply import [`dom_global_s
1515
```js
1616
/*
1717
Use a bundler or importmap to alias this import to one of:
18-
https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/dom_global_native.mjs
19-
https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/dom_global_shim.mjs
18+
https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/dom_global_native.mjs
19+
https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/dom_global_shim.mjs
2020
*/
2121
import * as dg from 'dom_global'
2222

docs/dom_readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
## Usage
1212

1313
```js
14-
import * as d from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/dom.mjs'
14+
import * as d from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/dom.mjs'
1515
```
1616

1717
## API

docs/dom_reg_readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
Example mockup for a pushstate link.
2828

2929
```js
30-
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/dom_reg.mjs'
30+
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/dom_reg.mjs'
3131

3232
// Immediately ready for use. Tag is automatically set to `a-btn`.
3333
// The mixin `MixReg` enables automatic registration on instantiation.
@@ -66,7 +66,7 @@ Apps which use server-side rendering and client-side upgrading of custom element
6666
Instead, use `dr.reg`, which is also used internally by `MixReg`. This is simply a shortcut for using the [#default registry](#class-reg) provided by this module.
6767

6868
```js
69-
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/dom_reg.mjs'
69+
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/dom_reg.mjs'
7070

7171
class Btn extends HTMLButtonElement {
7272
/*
@@ -106,7 +106,7 @@ For browser-only code, prefer the mixin `MixReg` from the same module which is e
106106
Simple usage:
107107

108108
```js
109-
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/dom_reg.mjs'
109+
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/dom_reg.mjs'
110110

111111
class Btn extends HTMLButtonElement {
112112
/*
@@ -126,7 +126,7 @@ document.body.append(new Btn())
126126
You can unset the default definer to defer registration:
127127

128128
```js
129-
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/dom_reg.mjs'
129+
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/dom_reg.mjs'
130130

131131
dr.Reg.main.setDefiner()
132132

docs/dom_shim_readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
## Usage
1212

1313
```js
14-
import * as ds from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/dom_shim.mjs'
14+
import * as ds from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/dom_shim.mjs'
1515
```
1616

1717
## API

docs/http_deno_readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Also see [`http`](http_readme.md) for routing and cookies, and [`live_deno`](liv
1919
Simple example of a server that serves files from the current directory, automatically matching URL paths to HTML files:
2020

2121
```js
22-
import * as hd from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.74/http_deno.mjs'
22+
import * as hd from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.75/http_deno.mjs'
2323

2424
// Finds files in the current folder, with no filtering.
2525
const DIRS = hd.Dirs.of(hd.dirRel(`.`))

0 commit comments

Comments
 (0)