@hybridly/core 0.10.0-beta.17 → 0.10.0-beta.18

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.
Files changed (2) hide show
  1. package/dist/index.mjs +14 -12
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -585,6 +585,9 @@ function createPromiseWithResolvers() {
585
585
  reject
586
586
  };
587
587
  }
588
+ function evaluateConditionalOption(options, option) {
589
+ return typeof option === "function" ? option(options) : option;
590
+ }
588
591
  //#endregion
589
592
  //#region src/router/request/request.ts
590
593
  function createPendingHybridRequest(options) {
@@ -709,13 +712,10 @@ async function navigate(options) {
709
712
  options.payload ??= payloadFromContext();
710
713
  options.payload.view ??= payloadFromContext().view;
711
714
  options.payload.view.properties = options.properties ?? options.payload.view.properties;
712
- function evaluateConditionalOption(option) {
713
- return typeof option === "function" ? option(options) : option;
714
- }
715
- const shouldPreserveState = evaluateConditionalOption(options.preserveState);
716
- const shouldPreserveScroll = evaluateConditionalOption(options.preserveScroll);
717
- const shouldReplaceHistory = evaluateConditionalOption(options.replace);
718
- const shouldReplaceUrl = evaluateConditionalOption(options.preserveUrl);
715
+ const shouldPreserveState = evaluateConditionalOption(options, options.preserveState);
716
+ const shouldPreserveScroll = evaluateConditionalOption(options, options.preserveScroll);
717
+ const shouldReplaceHistory = evaluateConditionalOption(options, options.replace);
718
+ const shouldReplaceUrl = evaluateConditionalOption(options, options.preserveUrl);
719
719
  const shouldPreserveView = !options.payload.view.component;
720
720
  if (shouldPreserveState && getHistoryMemo() && options.payload.view.component === context.view.component) {
721
721
  debug.history("Setting the memo from this history entry into the current context.");
@@ -888,7 +888,7 @@ async function handleHybridRequestResponse({ request, response }) {
888
888
  if (options.mode !== "async" || context.view.component === request.view.component) {
889
889
  const properties = (() => {
890
890
  if (!payload.view && !isPartial(options)) return;
891
- if (!payload.view.component || payload.view.component === context.view.component) return resolveProperties(context.view.properties, payload.view);
891
+ if (!payload.view.component || payload.view.component === context.view.component) return resolveProperties(context.view.properties, payload.view, { mergeWithOriginal: evaluateConditionalOption(options, options.preserveState) !== false });
892
892
  })();
893
893
  if (properties) debug.router("Merged properties:", properties);
894
894
  await navigate({
@@ -919,13 +919,15 @@ function isHybridResponse(response) {
919
919
  return response.headers.has(HYBRIDLY_HEADER);
920
920
  }
921
921
  function isPartial(options) {
922
- return options.only !== void 0 || options.except !== void 0;
922
+ return options.only !== void 0 || options.except !== void 0 || options.reset !== void 0;
923
923
  }
924
- function resolveProperties(original, payload) {
925
- const mergedPayloadProperties = merge(original, payload.properties);
926
- (payload.mergeable ?? []).forEach(([mergeableProperty, prepends, uniqueBy]) => {
924
+ function resolveProperties(original, payload, options) {
925
+ const mergeable = payload.mergeable ?? [];
926
+ const mergedPayloadProperties = options.mergeWithOriginal ? merge(original, payload.properties) : payload.properties;
927
+ mergeable.forEach(([mergeableProperty, prepends, uniqueBy]) => {
927
928
  const originalValue = get(original, mergeableProperty);
928
929
  const newValue = get(payload.properties, mergeableProperty);
930
+ if (!options.mergeWithOriginal && newValue === void 0) return;
929
931
  const mergeArrays = (current, incoming) => {
930
932
  const merged = prepends === true ? [...incoming, ...current] : [...current, ...incoming];
931
933
  if (typeof uniqueBy !== "string") return merged;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hybridly/core",
3
3
  "type": "module",
4
- "version": "0.10.0-beta.17",
4
+ "version": "0.10.0-beta.18",
5
5
  "description": "Core functionality of Hybridly",
6
6
  "author": "Enzo Innocenzi <enzo@innocenzi.dev>",
7
7
  "license": "MIT",
@@ -40,7 +40,7 @@
40
40
  "build:stub": "obuild --stub"
41
41
  },
42
42
  "dependencies": {
43
- "@hybridly/utils": "0.10.0-beta.17",
43
+ "@hybridly/utils": "0.10.0-beta.18",
44
44
  "neoqs": "^6.13.0",
45
45
  "superjson": "^2.2.2",
46
46
  "es-toolkit": "^1.45.1"