@b9g/crank 0.7.7 → 0.7.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b9g/crank",
3
- "version": "0.7.7",
3
+ "version": "0.7.8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/bikeshaving/crank.git"
package/umd.js CHANGED
@@ -250,6 +250,24 @@
250
250
  delegates.clear();
251
251
  }
252
252
 
253
+ const supportsUserTiming = typeof performance !== "undefined" && typeof performance.mark === "function";
254
+ function markStart(label) {
255
+ if (supportsUserTiming) {
256
+ performance.mark("⚙ " + label);
257
+ }
258
+ }
259
+ function measureMark(label) {
260
+ if (supportsUserTiming) {
261
+ const name = "⚙ " + label;
262
+ try {
263
+ performance.measure(name, name);
264
+ }
265
+ catch (_) {
266
+ // Mark may not exist
267
+ }
268
+ performance.clearMarks(name);
269
+ }
270
+ }
253
271
  function wrap(value) {
254
272
  return value === undefined ? [] : Array.isArray(value) ? value : [value];
255
273
  }
@@ -770,11 +788,16 @@
770
788
  return ret;
771
789
  }
772
790
  function renderRoot(adapter, root, ret, children) {
791
+ const commitLabel = "commit (" + getTagName(ret.el.tag) + ")";
792
+ markStart("diff");
773
793
  const diff = diffChildren(adapter, root, ret, ret.ctx, ret.scope, ret, children);
774
794
  const schedulePromises = [];
775
795
  if (isPromiseLike(diff)) {
776
796
  return diff.then(() => {
797
+ measureMark("diff");
798
+ markStart(commitLabel);
777
799
  commit(adapter, ret, ret, ret.ctx, ret.scope, root, 0, schedulePromises, undefined);
800
+ measureMark(commitLabel);
778
801
  if (schedulePromises.length > 0) {
779
802
  return Promise.all(schedulePromises).then(() => {
780
803
  if (typeof root !== "object" || root === null) {
@@ -789,7 +812,10 @@
789
812
  return adapter.read(unwrap(getChildValues(ret)));
790
813
  });
791
814
  }
815
+ measureMark("diff");
816
+ markStart(commitLabel);
792
817
  commit(adapter, ret, ret, ret.ctx, ret.scope, root, 0, schedulePromises, undefined);
818
+ measureMark(commitLabel);
793
819
  if (schedulePromises.length > 0) {
794
820
  return Promise.all(schedulePromises).then(() => {
795
821
  if (typeof root !== "object" || root === null) {
@@ -1891,6 +1917,7 @@
1891
1917
  if (getFlag(ctx.ret, IsScheduling)) {
1892
1918
  setFlag(ctx.ret, IsSchedulingRefresh);
1893
1919
  }
1920
+ const commitLabel = "commit (" + getTagName(ctx.ret.el.tag) + ")";
1894
1921
  let diff;
1895
1922
  const schedulePromises = [];
1896
1923
  try {
@@ -1898,7 +1925,12 @@
1898
1925
  diff = enqueueComponent(ctx);
1899
1926
  if (isPromiseLike(diff)) {
1900
1927
  return diff
1901
- .then(() => ctx.adapter.read(commitComponent(ctx, schedulePromises)))
1928
+ .then(() => {
1929
+ markStart(commitLabel);
1930
+ const value = commitComponent(ctx, schedulePromises);
1931
+ measureMark(commitLabel);
1932
+ return ctx.adapter.read(value);
1933
+ })
1902
1934
  .then((result) => {
1903
1935
  if (schedulePromises.length) {
1904
1936
  return Promise.all(schedulePromises).then(() => {
@@ -1928,7 +1960,9 @@
1928
1960
  })
1929
1961
  .finally(() => setFlag(ctx.ret, IsRefreshing, false));
1930
1962
  }
1963
+ markStart(commitLabel);
1931
1964
  const result = ctx.adapter.read(commitComponent(ctx, schedulePromises));
1965
+ measureMark(commitLabel);
1932
1966
  if (schedulePromises.length) {
1933
1967
  return Promise.all(schedulePromises).then(() => {
1934
1968
  return ctx.adapter.read(getValue(ctx.ret));
@@ -2158,11 +2192,13 @@
2158
2192
  }
2159
2193
  const ret = ctx.ret;
2160
2194
  const initial = !ctx.iterator;
2195
+ const tagName = getTagName(ret.el.tag);
2161
2196
  if (initial) {
2162
2197
  setFlag(ctx.ret, IsExecuting);
2163
2198
  clearEventListeners(ctx.ctx);
2164
2199
  let returned;
2165
2200
  try {
2201
+ markStart(tagName);
2166
2202
  returned = ret.el.tag.call(ctx.ctx, ret.el.props, ctx.ctx);
2167
2203
  }
2168
2204
  catch (err) {
@@ -2177,6 +2213,7 @@
2177
2213
  }
2178
2214
  else if (!isPromiseLike(returned)) {
2179
2215
  // sync function component
2216
+ measureMark(tagName);
2180
2217
  return [
2181
2218
  undefined,
2182
2219
  diffComponentChildren(ctx, returned, false),
@@ -2185,6 +2222,7 @@
2185
2222
  else {
2186
2223
  // async function component
2187
2224
  const returned1 = returned instanceof Promise ? returned : Promise.resolve(returned);
2225
+ returned1.then(() => measureMark(tagName), () => measureMark(tagName));
2188
2226
  return [
2189
2227
  returned1.catch(NOOP),
2190
2228
  returned1.then((returned) => diffComponentChildren(ctx, returned, false), (err) => {
@@ -2198,6 +2236,7 @@
2198
2236
  if (initial) {
2199
2237
  try {
2200
2238
  setFlag(ctx.ret, IsExecuting);
2239
+ markStart(tagName);
2201
2240
  iteration = ctx.iterator.next();
2202
2241
  }
2203
2242
  catch (err) {
@@ -2220,7 +2259,9 @@
2220
2259
  try {
2221
2260
  setFlag(ctx.ret, IsExecuting);
2222
2261
  const oldResult = ctx.adapter.read(getValue(ctx.ret));
2262
+ markStart(tagName);
2223
2263
  iteration = ctx.iterator.next(oldResult);
2264
+ measureMark(tagName);
2224
2265
  }
2225
2266
  catch (err) {
2226
2267
  setFlag(ctx.ret, IsErrored);
@@ -2230,6 +2271,9 @@
2230
2271
  setFlag(ctx.ret, IsExecuting, false);
2231
2272
  }
2232
2273
  }
2274
+ else {
2275
+ measureMark(tagName);
2276
+ }
2233
2277
  if (isPromiseLike(iteration)) {
2234
2278
  throw new Error("Mixed generator component");
2235
2279
  }
@@ -2252,6 +2296,7 @@
2252
2296
  else {
2253
2297
  if (getFlag(ctx.ret, IsInForAwaitOfLoop)) {
2254
2298
  // initializes the async generator loop
2299
+ measureMark(tagName);
2255
2300
  pullComponent(ctx, iteration);
2256
2301
  const block = resumePropsAsyncIterator(ctx);
2257
2302
  return [block, ctx.pull && ctx.pull.diff];
@@ -2264,6 +2309,7 @@
2264
2309
  try {
2265
2310
  setFlag(ctx.ret, IsExecuting);
2266
2311
  const oldResult = ctx.adapter.read(getValue(ctx.ret));
2312
+ markStart(tagName);
2267
2313
  iteration = ctx.iterator.next(oldResult);
2268
2314
  }
2269
2315
  catch (err) {
@@ -2277,6 +2323,7 @@
2277
2323
  if (!isPromiseLike(iteration)) {
2278
2324
  throw new Error("Mixed generator component");
2279
2325
  }
2326
+ iteration.then(() => measureMark(tagName), () => measureMark(tagName));
2280
2327
  const diff = iteration.then((iteration) => {
2281
2328
  if (getFlag(ctx.ret, IsInForAwaitOfLoop)) {
2282
2329
  // We have entered a for await...of loop, so we start pulling
@@ -2671,7 +2718,7 @@
2671
2718
  }
2672
2719
  }
2673
2720
  let didLinger = false;
2674
- if (!isNested && cleanupPromises && getChildValues(ctx.ret).length > 0) {
2721
+ if (!isNested && cleanupPromises) {
2675
2722
  didLinger = true;
2676
2723
  const index = ctx.index;
2677
2724
  const lingerers = ctx.host.lingerers || (ctx.host.lingerers = []);