mol_wire_lib 1.0.1182 → 1.0.1184

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/web.mjs CHANGED
@@ -1455,10 +1455,19 @@ var $;
1455
1455
  "use strict";
1456
1456
  var $;
1457
1457
  (function ($) {
1458
+ const factories = new WeakMap();
1459
+ function factory(val) {
1460
+ let make = factories.get(val);
1461
+ if (make)
1462
+ return make;
1463
+ make = $mol_func_name_from((...args) => new val(...args), val);
1464
+ factories.set(val, make);
1465
+ return make;
1466
+ }
1458
1467
  function $mol_wire_sync(obj) {
1459
1468
  return new Proxy(obj, {
1460
1469
  get(obj, field) {
1461
- const val = obj[field];
1470
+ let val = obj[field];
1462
1471
  if (typeof val !== 'function')
1463
1472
  return val;
1464
1473
  const temp = $mol_wire_task.getter(val);
@@ -1467,10 +1476,13 @@ var $;
1467
1476
  return fiber.sync();
1468
1477
  };
1469
1478
  },
1479
+ construct(obj, args) {
1480
+ const temp = $mol_wire_task.getter(factory(obj));
1481
+ return temp(obj, args).sync();
1482
+ },
1470
1483
  apply(obj, self, args) {
1471
1484
  const temp = $mol_wire_task.getter(obj);
1472
- const fiber = temp(self, args);
1473
- return fiber.sync();
1485
+ return temp(self, args).sync();
1474
1486
  },
1475
1487
  });
1476
1488
  }
package/web.test.js CHANGED
@@ -1307,24 +1307,6 @@ var $;
1307
1307
  });
1308
1308
  })($ || ($ = {}));
1309
1309
 
1310
- ;
1311
- "use strict";
1312
- var $;
1313
- (function ($_1) {
1314
- $mol_test({
1315
- 'test types'($) {
1316
- class A {
1317
- static a() {
1318
- return Promise.resolve('');
1319
- }
1320
- static b() {
1321
- return $mol_wire_sync(this).a();
1322
- }
1323
- }
1324
- },
1325
- });
1326
- })($ || ($ = {}));
1327
-
1328
1310
  ;
1329
1311
  "use strict";
1330
1312
  var $;
@@ -1378,6 +1360,59 @@ var $;
1378
1360
  });
1379
1361
  })($ || ($ = {}));
1380
1362
 
1363
+ ;
1364
+ "use strict";
1365
+ var $;
1366
+ (function ($_1) {
1367
+ $mol_test({
1368
+ 'test types'($) {
1369
+ class A {
1370
+ static a() {
1371
+ return Promise.resolve('');
1372
+ }
1373
+ static b() {
1374
+ return $mol_wire_sync(this).a();
1375
+ }
1376
+ }
1377
+ },
1378
+ async 'test method from host'($) {
1379
+ let count = 0;
1380
+ class A {
1381
+ static a() {
1382
+ return $mol_wire_sync(this).b();
1383
+ }
1384
+ static b() { return Promise.resolve(++count); }
1385
+ }
1386
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
1387
+ },
1388
+ async 'test function'($) {
1389
+ let count = 0;
1390
+ class A {
1391
+ static a() {
1392
+ return $mol_wire_sync(this.b)();
1393
+ }
1394
+ static b() { return Promise.resolve(++count); }
1395
+ }
1396
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
1397
+ },
1398
+ async 'test construct itself'($) {
1399
+ class A {
1400
+ static instances = [];
1401
+ static a() {
1402
+ const a = new ($mol_wire_sync(A))();
1403
+ this.instances.push(a);
1404
+ $mol_wire_sync(this).b();
1405
+ }
1406
+ static b() { return Promise.resolve(); }
1407
+ }
1408
+ await $mol_wire_async(A).a();
1409
+ $mol_assert_equal(A.instances.length, 2);
1410
+ $mol_assert_equal(A.instances[0] instanceof A);
1411
+ $mol_assert_equal(A.instances[0], A.instances[1]);
1412
+ }
1413
+ });
1414
+ })($ || ($ = {}));
1415
+
1381
1416
  ;
1382
1417
  "use strict";
1383
1418
  var $;