aoye 0.0.46 → 0.0.48

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/dist/index.umd.js CHANGED
@@ -27,6 +27,12 @@
27
27
  ScheduleType[ScheduleType["Post"] = 8] = "Post";
28
28
  return ScheduleType;
29
29
  }({});
30
+ const EffectStrType2Enum = {
31
+ sync: ScheduleType.Sync,
32
+ pre: ScheduleType.Pre,
33
+ render: ScheduleType.Render,
34
+ post: ScheduleType.Post
35
+ };
30
36
  let ScheduleStatus = function (ScheduleStatus) {
31
37
  ScheduleStatus[ScheduleStatus["Idle"] = 0] = "Idle";
32
38
  ScheduleStatus[ScheduleStatus["Ready"] = 1] = "Ready";
@@ -713,6 +719,19 @@
713
719
  }
714
720
  }
715
721
  }
722
+ class NoopEffect {
723
+ constructor(callback) {
724
+ this.callback = callback;
725
+ const scope = new Scope(callback);
726
+ scope.get();
727
+ return scope;
728
+ }
729
+ }
730
+ const noopEffect = callback => {
731
+ const scope = new Scope(callback);
732
+ scope.get();
733
+ return scope;
734
+ };
716
735
  Scope.prototype.dispose = dispose;
717
736
 
718
737
  const rawToProxy = new WeakMap();
@@ -1258,14 +1277,16 @@
1258
1277
  };
1259
1278
  }
1260
1279
  }
1261
- ({
1262
- type: ScheduleType.Sync
1263
- });
1280
+ const DefaultCustomEffectOpt = {
1281
+ immediate: true,
1282
+ type: 'sync'
1283
+ };
1264
1284
  function effectUt(callback, depOrOpt, opt) {
1265
1285
  const hasDep = Array.isArray(depOrOpt);
1266
1286
  opt = hasDep ? opt || {} : depOrOpt || {};
1287
+ const scheduleType = EffectStrType2Enum[opt.type];
1267
1288
  if (!hasDep) {
1268
- const ef = new Effect(callback, opt.type);
1289
+ const ef = new Effect(callback, scheduleType);
1269
1290
  const run = ef.dispose.bind(ef);
1270
1291
  run.ins = ef;
1271
1292
  return run;
@@ -1291,7 +1312,7 @@
1291
1312
  eff.state &= -257;
1292
1313
  }
1293
1314
  mounted = true;
1294
- }, opt.type);
1315
+ }, scheduleType);
1295
1316
  const run = ef.dispose.bind(ef);
1296
1317
  run.ins = ef;
1297
1318
  return run;
@@ -1299,8 +1320,13 @@
1299
1320
  function effect(callback, depOrOpt, opt) {
1300
1321
  const hasDep = Array.isArray(depOrOpt);
1301
1322
  opt = hasDep ? opt || {} : depOrOpt || {};
1323
+ opt = {
1324
+ ...DefaultCustomEffectOpt,
1325
+ ...opt
1326
+ };
1327
+ const scheduleType = EffectStrType2Enum[opt.type];
1302
1328
  if (!hasDep) {
1303
- const ef = new Effect(callback, opt.type);
1329
+ const ef = new Effect(callback, scheduleType);
1304
1330
  return ef;
1305
1331
  }
1306
1332
  let mounted = false;
@@ -1314,7 +1340,8 @@
1314
1340
  }));
1315
1341
  const ef = new Effect(eff => {
1316
1342
  for (let i = 0; i < deps.length; i++) {
1317
- const value = deps[i].get();
1343
+ const dep = deps[i];
1344
+ const value = typeof dep === 'function' ? dep() : dep.get();
1318
1345
  vs[i].old = vs[i].val;
1319
1346
  vs[i].val = value;
1320
1347
  }
@@ -1324,7 +1351,7 @@
1324
1351
  eff.state &= -257;
1325
1352
  }
1326
1353
  mounted = true;
1327
- }, opt.type);
1354
+ }, scheduleType);
1328
1355
  return ef;
1329
1356
  }
1330
1357
  function scope(...args) {
@@ -1341,8 +1368,10 @@
1341
1368
  exports.$ = $;
1342
1369
  exports.Computed = Computed;
1343
1370
  exports.Effect = Effect;
1371
+ exports.EffectStrType2Enum = EffectStrType2Enum;
1344
1372
  exports.IsStore = IsStore;
1345
1373
  exports.Keys = Keys;
1374
+ exports.NoopEffect = NoopEffect;
1346
1375
  exports.ScheduleStatus = ScheduleStatus;
1347
1376
  exports.ScheduleType = ScheduleType;
1348
1377
  exports.Scope = Scope;
@@ -1361,6 +1390,7 @@
1361
1390
  exports.ide = ide;
1362
1391
  exports.macro = macro;
1363
1392
  exports.micro = micro;
1393
+ exports.noopEffect = noopEffect;
1364
1394
  exports.now = now;
1365
1395
  exports.runWithPulling = runWithPulling;
1366
1396
  exports.scope = scope;