@farm.js/react 0.1.0-beta.4 → 0.1.0-beta.5

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/README.md CHANGED
@@ -32,6 +32,19 @@ binding. The runtime uses direct subscription indexes rather than proxies or a c
32
32
  scan. Use `compiler: { reactivity: "static" }` to retain only the complete build-time dependency
33
33
  lists for comparison or diagnosis.
34
34
 
35
+ Compiler output also selects its runtime capabilities at build time. A direct counter imports only
36
+ the cell scheduler and direct-binding core; conditionals, keyed rows and LIS, nested host ranges,
37
+ and component islands are retained only when a compiled component in that module needs them. Plain
38
+ keyed rows omit the larger recursive-host and row-conditional extensions. This selection is
39
+ automatic and does not add a configuration option or asynchronous runtime loading. The legacy
40
+ `createCompiledComponent` export remains a complete compatibility entry for hand-authored
41
+ definitions, while generated code uses the tree-shakable feature entry.
42
+
43
+ The persisted production-size fixtures and regression gate live in
44
+ [`RUNTIME_SIZE_RESULTS.md`](./RUNTIME_SIZE_RESULTS.md). The recorded direct-only runtime premium is
45
+ 73.6% smaller than the complete compatibility runtime premium; the feature-heavy keyed benchmark
46
+ application removes 6,185 gzip bytes from its previous compiler-on build.
47
+
35
48
  For selective adoption, use annotation mode:
36
49
 
37
50
  ```ts
@@ -1883,11 +1883,7 @@ function longestIncreasingSubsequencePositions(sequence) {
1883
1883
  }
1884
1884
  return positions;
1885
1885
  }
1886
- function createKeyedRowsBlockComponent(owner) {
1887
- const rowHostScopeOwner = {
1888
- subscribe: () => () => {
1889
- }
1890
- };
1886
+ function createKeyedRowConditionalRuntime() {
1891
1887
  class FarmKeyedRowConditional extends React__default.default.Component {
1892
1888
  constructor() {
1893
1889
  super(...arguments);
@@ -1929,6 +1925,22 @@ function createKeyedRowsBlockComponent(owner) {
1929
1925
  }
1930
1926
  }
1931
1927
  FarmKeyedRowConditional.displayName = "FarmCompiledKeyedRowConditional";
1928
+ return {
1929
+ Component: FarmKeyedRowConditional,
1930
+ readValues: readKeyedRowConditionalValues,
1931
+ changed: keyedRowConditionalChanged
1932
+ };
1933
+ }
1934
+ function createKeyedRowHostRuntime() {
1935
+ const owner = {
1936
+ subscribe: () => () => {
1937
+ }
1938
+ };
1939
+ return {
1940
+ mount: (element, descriptor, requestFallback) => mountCompilerHostTree(owner, element, descriptor, requestFallback)
1941
+ };
1942
+ }
1943
+ function createKeyedRowsBlockComponent(owner, options = {}) {
1932
1944
  class FarmKeyedRowsBlock extends React__default.default.Component {
1933
1945
  constructor() {
1934
1946
  super(...arguments);
@@ -2001,7 +2013,9 @@ function createKeyedRowsBlockComponent(owner) {
2001
2013
  this.rowConditional = (item, index, conditionalId, render) => {
2002
2014
  if (this.state.fallback) return render(item, index);
2003
2015
  const key = keyedRowIdentity(this.currentProps.rowKey(item, index));
2004
- return React__default.default.createElement(FarmKeyedRowConditional, {
2016
+ const Conditional = options.conditionals?.Component;
2017
+ if (!Conditional) return render(item, index);
2018
+ return React__default.default.createElement(Conditional, {
2005
2019
  key: `${key}:${conditionalId}`,
2006
2020
  owner: this.conditionalOwner,
2007
2021
  rowKey: key,
@@ -2095,12 +2109,10 @@ function createKeyedRowsBlockComponent(owner) {
2095
2109
  }
2096
2110
  mountRowHostScope(element, descriptor, props = this.currentProps) {
2097
2111
  if (!props.hostBlocks) return void 0;
2098
- return mountCompilerHostTree(
2099
- rowHostScopeOwner,
2100
- element,
2101
- descriptor,
2102
- this.requestHostScopeFallback
2103
- );
2112
+ return options.hostBlocks?.mount(element, descriptor, this.requestHostScopeFallback) || null;
2113
+ }
2114
+ readConditionalValues(props, item, index) {
2115
+ return options.conditionals?.readValues(props, item, index) || EMPTY_KEYED_ROW_CONDITIONAL_VALUES;
2104
2116
  }
2105
2117
  pruneEventHandlers(keys) {
2106
2118
  const active = new Set(keys);
@@ -2141,7 +2153,7 @@ function createKeyedRowsBlockComponent(owner) {
2141
2153
  values: this.hasReactOwnedRows() ? this.currentProps.bindings.map(() => UNSET_KEYED_ROW_BINDING) : readKeyedRowBindingValues(this.currentProps, rows.items[index], index),
2142
2154
  item: rows.items[index],
2143
2155
  index,
2144
- conditionalValues: readKeyedRowConditionalValues(
2156
+ conditionalValues: this.readConditionalValues(
2145
2157
  this.currentProps,
2146
2158
  rows.items[index],
2147
2159
  index
@@ -2253,13 +2265,13 @@ function createKeyedRowsBlockComponent(owner) {
2253
2265
  }
2254
2266
  }
2255
2267
  applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
2256
- const conditionalValues = readKeyedRowConditionalValues(
2268
+ const conditionalValues = this.readConditionalValues(
2257
2269
  this.currentProps,
2258
2270
  rows.items[index],
2259
2271
  index
2260
2272
  );
2261
2273
  for (const [id, values] of conditionalValues) {
2262
- if (keyedRowConditionalChanged(existing.conditionalValues.get(id), values)) {
2274
+ if (options.conditionals?.changed(existing.conditionalValues.get(id), values)) {
2263
2275
  conditionalChanges.push({ key, id, item: rows.items[index], index });
2264
2276
  }
2265
2277
  }
@@ -2296,13 +2308,13 @@ function createKeyedRowsBlockComponent(owner) {
2296
2308
  }
2297
2309
  }
2298
2310
  applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
2299
- const conditionalValues = readKeyedRowConditionalValues(
2311
+ const conditionalValues = this.readConditionalValues(
2300
2312
  this.currentProps,
2301
2313
  rows.items[index],
2302
2314
  index
2303
2315
  );
2304
2316
  for (const [id, values] of conditionalValues) {
2305
- if (keyedRowConditionalChanged(existing.conditionalValues.get(id), values)) {
2317
+ if (options.conditionals?.changed(existing.conditionalValues.get(id), values)) {
2306
2318
  conditionalChanges.push({ key, id, item: rows.items[index], index });
2307
2319
  }
2308
2320
  }
@@ -2386,13 +2398,13 @@ function createKeyedRowsBlockComponent(owner) {
2386
2398
  }
2387
2399
  }
2388
2400
  applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
2389
- const conditionalValues = readKeyedRowConditionalValues(
2401
+ const conditionalValues = this.readConditionalValues(
2390
2402
  this.currentProps,
2391
2403
  rows.items[index],
2392
2404
  index
2393
2405
  );
2394
2406
  for (const [id, values] of conditionalValues) {
2395
- if (keyedRowConditionalChanged(existing.conditionalValues.get(id), values)) {
2407
+ if (options.conditionals?.changed(existing.conditionalValues.get(id), values)) {
2396
2408
  conditionalChanges.push({ key, id, item: rows.items[index], index });
2397
2409
  }
2398
2410
  }
@@ -2419,7 +2431,7 @@ function createKeyedRowsBlockComponent(owner) {
2419
2431
  values: readKeyedRowBindingValues(this.currentProps, rows.items[index], index),
2420
2432
  item: rows.items[index],
2421
2433
  index,
2422
- conditionalValues: readKeyedRowConditionalValues(
2434
+ conditionalValues: this.readConditionalValues(
2423
2435
  this.currentProps,
2424
2436
  rows.items[index],
2425
2437
  index
@@ -2898,12 +2910,86 @@ function createComponentBlockComponent(owner) {
2898
2910
  FarmComponentBlock.displayName = "FarmCompiledComponentIsland";
2899
2911
  return FarmComponentBlock;
2900
2912
  }
2901
- function createCompiledComponent(definition) {
2913
+ var conditionalRuntimeFeature = {
2914
+ name: "conditional",
2915
+ create: (owner) => ({
2916
+ Conditional: createConditionalBlockComponent(owner)
2917
+ })
2918
+ };
2919
+ var hostConditionalRuntimeFeature = {
2920
+ name: "host-conditional",
2921
+ create: (owner) => ({
2922
+ HostConditional: createHostConditionalBlockComponent(owner)
2923
+ })
2924
+ };
2925
+ var conditionalRangesRuntimeFeature = {
2926
+ name: "conditional-ranges",
2927
+ create: (owner) => ({
2928
+ ConditionalRanges: createConditionalRangesBlockComponent(owner)
2929
+ })
2930
+ };
2931
+ var keyedListRuntimeFeature = {
2932
+ name: "keyed-list",
2933
+ create: (owner) => ({
2934
+ KeyedList: createKeyedListBlockComponent(owner)
2935
+ })
2936
+ };
2937
+ var keyedRowsRuntimeFeature = {
2938
+ name: "keyed-rows",
2939
+ create: (owner) => ({
2940
+ KeyedRows: createKeyedRowsBlockComponent(owner)
2941
+ })
2942
+ };
2943
+ var keyedRowsConditionalRuntimeFeature = {
2944
+ name: "keyed-rows:conditional",
2945
+ create: (owner) => ({
2946
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
2947
+ conditionals: createKeyedRowConditionalRuntime()
2948
+ })
2949
+ })
2950
+ };
2951
+ var keyedRowsHostRuntimeFeature = {
2952
+ name: "keyed-rows:host",
2953
+ create: (owner) => ({
2954
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
2955
+ hostBlocks: createKeyedRowHostRuntime()
2956
+ })
2957
+ })
2958
+ };
2959
+ var keyedRowsCompleteRuntimeFeature = {
2960
+ name: "keyed-rows:complete",
2961
+ create: (owner) => ({
2962
+ KeyedRows: createKeyedRowsBlockComponent(owner, {
2963
+ conditionals: createKeyedRowConditionalRuntime(),
2964
+ hostBlocks: createKeyedRowHostRuntime()
2965
+ })
2966
+ })
2967
+ };
2968
+ var keyedRangesRuntimeFeature = {
2969
+ name: "keyed-ranges",
2970
+ create: (owner) => ({
2971
+ KeyedRanges: createKeyedRangesBlockComponent(owner)
2972
+ })
2973
+ };
2974
+ var mixedRangesRuntimeFeature = {
2975
+ name: "mixed-ranges",
2976
+ create: (owner) => ({
2977
+ MixedRanges: createMixedRangesBlockComponent(owner)
2978
+ })
2979
+ };
2980
+ var componentRuntimeFeature = {
2981
+ name: "component",
2982
+ create: (owner) => ({
2983
+ Component: createComponentBlockComponent(owner)
2984
+ })
2985
+ };
2986
+ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
2902
2987
  const stateSignature = definition.stateSignature || String(definition.initialize.length);
2988
+ const runtimeSignature = [...new Set(runtimeFeatures.map((feature) => feature.name))].sort().join(",");
2903
2989
  if (definition.hmrId) {
2904
2990
  const registry = getCompilerHmrRegistry();
2905
2991
  const existing = registry.get(definition.hmrId);
2906
- if (existing?.stateSignature === stateSignature) {
2992
+ if (existing?.stateSignature === stateSignature && existing.runtimeSignature === runtimeSignature) {
2907
2993
  existing.definition.current = definition;
2908
2994
  existing.component.displayName = `FarmCompiled(${definition.displayName})`;
2909
2995
  for (const refresh of existing.refreshListeners) refresh();
@@ -2977,34 +3063,17 @@ function createCompiledComponent(definition) {
2977
3063
  }
2978
3064
  };
2979
3065
  });
2980
- this.blockRuntime = {
2981
- Conditional: createConditionalBlockComponent({
2982
- setRoot: (id, root) => this.setBlockRoot(id, root),
2983
- subscribe: (id, refresh) => this.subscribeToBlock(id, refresh)
2984
- }),
2985
- HostConditional: createHostConditionalBlockComponent({
2986
- subscribe: (id, refresh) => this.subscribeToBlock(id, refresh)
2987
- }),
2988
- ConditionalRanges: createConditionalRangesBlockComponent({
2989
- subscribe: (id, refresh) => this.subscribeToBlock(id, refresh)
2990
- }),
2991
- KeyedList: createKeyedListBlockComponent({
2992
- subscribe: (id, refresh) => this.subscribeToBlock(id, refresh)
2993
- }),
2994
- KeyedRows: createKeyedRowsBlockComponent({
2995
- subscribe: (id, refresh) => this.subscribeToBlock(id, refresh)
2996
- }),
2997
- KeyedRanges: createKeyedRangesBlockComponent({
2998
- subscribe: (id, refresh) => this.subscribeToBlock(id, refresh)
2999
- }),
3000
- MixedRanges: createMixedRangesBlockComponent({
3001
- subscribe: (id, refresh) => this.subscribeToBlock(id, refresh)
3002
- }),
3003
- Component: createComponentBlockComponent({
3004
- subscribe: (id, refresh) => this.subscribeToBlock(id, refresh)
3005
- }),
3066
+ const featureOwner = {
3067
+ setRoot: (id, root) => this.setBlockRoot(id, root),
3068
+ subscribe: (id, refresh) => this.subscribeToBlock(id, refresh)
3069
+ };
3070
+ const blockRuntime = {
3006
3071
  target: (id) => this.bindingTarget(id)
3007
3072
  };
3073
+ for (const feature of runtimeFeatures) {
3074
+ Object.assign(blockRuntime, feature.create(featureOwner));
3075
+ }
3076
+ this.blockRuntime = blockRuntime;
3008
3077
  }
3009
3078
  usesHybridReactivity() {
3010
3079
  return definitionReference.current.reactivity === "hybrid";
@@ -3355,12 +3424,38 @@ function createCompiledComponent(definition) {
3355
3424
  component,
3356
3425
  definition: definitionReference,
3357
3426
  refreshListeners,
3358
- stateSignature
3427
+ stateSignature,
3428
+ runtimeSignature
3359
3429
  });
3360
3430
  }
3361
3431
  return component;
3362
3432
  }
3433
+ var COMPLETE_RUNTIME_FEATURES = [
3434
+ conditionalRuntimeFeature,
3435
+ hostConditionalRuntimeFeature,
3436
+ conditionalRangesRuntimeFeature,
3437
+ keyedListRuntimeFeature,
3438
+ keyedRowsCompleteRuntimeFeature,
3439
+ keyedRangesRuntimeFeature,
3440
+ mixedRangesRuntimeFeature,
3441
+ componentRuntimeFeature
3442
+ ];
3443
+ function createCompiledComponent(definition) {
3444
+ return createCompiledComponentWithFeatures(definition, COMPLETE_RUNTIME_FEATURES);
3445
+ }
3363
3446
 
3447
+ exports.componentRuntimeFeature = componentRuntimeFeature;
3448
+ exports.conditionalRangesRuntimeFeature = conditionalRangesRuntimeFeature;
3449
+ exports.conditionalRuntimeFeature = conditionalRuntimeFeature;
3364
3450
  exports.createCompiledComponent = createCompiledComponent;
3451
+ exports.createCompiledComponentWithFeatures = createCompiledComponentWithFeatures;
3452
+ exports.hostConditionalRuntimeFeature = hostConditionalRuntimeFeature;
3453
+ exports.keyedListRuntimeFeature = keyedListRuntimeFeature;
3454
+ exports.keyedRangesRuntimeFeature = keyedRangesRuntimeFeature;
3455
+ exports.keyedRowsCompleteRuntimeFeature = keyedRowsCompleteRuntimeFeature;
3456
+ exports.keyedRowsConditionalRuntimeFeature = keyedRowsConditionalRuntimeFeature;
3457
+ exports.keyedRowsHostRuntimeFeature = keyedRowsHostRuntimeFeature;
3458
+ exports.keyedRowsRuntimeFeature = keyedRowsRuntimeFeature;
3459
+ exports.mixedRangesRuntimeFeature = mixedRangesRuntimeFeature;
3365
3460
  //# sourceMappingURL=compiler-runtime.cjs.map
3366
3461
  //# sourceMappingURL=compiler-runtime.cjs.map