ripple 0.2.42 → 0.2.44

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.
@@ -1,5 +1,4 @@
1
1
  /** @import { Block, Component, Dependency, Computed, Tracked } from '#client' */
2
- /** @import { RippleArray } from 'ripple' */
3
2
 
4
3
  import {
5
4
  destroy_block,
@@ -26,10 +25,11 @@ import {
26
25
  TRACKED_OBJECT,
27
26
  TRY_BLOCK,
28
27
  UNINITIALIZED,
29
- USE_PROP,
28
+ REF_PROP,
29
+ ARRAY_SET_INDEX_AT,
30
30
  } from './constants';
31
31
  import { capture, suspend } from './try.js';
32
- import { define_property, get_descriptor, is_array } from './utils';
32
+ import { define_property, get_descriptor, is_ripple_array, is_positive_integer } from './utils';
33
33
  import {
34
34
  object_keys as original_object_keys,
35
35
  object_values as original_object_values,
@@ -858,6 +858,28 @@ export function computed_property(fn) {
858
858
  return fn;
859
859
  }
860
860
 
861
+ /**
862
+ * @param {any} obj
863
+ * @param {string | number | symbol} property
864
+ * @param {boolean} chain_obj
865
+ * @param {boolean} chain_prop
866
+ * @param {...any} args
867
+ * @returns {any}
868
+ */
869
+ export function call_property(obj, property, chain_obj, chain_prop, ...args) {
870
+ // don't swallow errors if either the object or property is nullish,
871
+ // respect optional chaining as provided
872
+ if(!chain_obj && !chain_prop) {
873
+ return obj[property].call(obj, ...args);
874
+ } else if (chain_obj && chain_prop) {
875
+ return obj?.[property]?.call(obj, ...args);
876
+ } else if (chain_obj) {
877
+ return obj?.[property].call(obj, ...args);
878
+ } else if (chain_prop) {
879
+ return obj[property]?.call(obj, ...args);
880
+ }
881
+ }
882
+
861
883
  /**
862
884
  * @param {any} obj
863
885
  * @param {string | number | symbol} property
@@ -881,6 +903,8 @@ export function get_property(obj, property, chain = false) {
881
903
  var spread_fn = obj[SPREAD_OBJECT];
882
904
  var properties = spread_fn();
883
905
  return get_property(properties, property, chain);
906
+ } else if (is_ripple_array(obj)) {
907
+ obj.$length;
884
908
  }
885
909
 
886
910
  return value;
@@ -894,20 +918,30 @@ export function get_property(obj, property, chain = false) {
894
918
  * @returns {any}
895
919
  */
896
920
  export function set_property(obj, property, value, block) {
897
- var res = (obj[property] = value);
898
921
  var tracked_properties = obj[TRACKED_OBJECT];
899
- var tracked = tracked_properties?.[property];
922
+ var rip_arr = is_ripple_array(obj);
923
+ var tracked = !(rip_arr && property === 'length') ? tracked_properties?.[property] : undefined;
900
924
 
901
925
  if (tracked === undefined) {
902
926
  // Handle computed assignments to arrays
903
- if (is_array(obj) && obj.$length && tracked_properties !== undefined) {
904
- with_scope(block, () => {
905
- obj.splice(/** @type {number} */ (property), 1, value);
906
- });
927
+ if (rip_arr) {
928
+ if (property === 'length') {
929
+ // overriding `length` in RippleArray class doesn't work
930
+ // placing it here instead
931
+ throw new Error('Cannot set length on RippleArray, use $length instead');
932
+ } else if (is_positive_integer(property)) {
933
+ // for any other type we use obj[property] = value below as per native JS
934
+ return with_scope(block, () => {
935
+ obj[ARRAY_SET_INDEX_AT](property, value);
936
+ });
937
+ }
907
938
  }
908
- return res;
939
+
940
+ return (obj[property] = value);
909
941
  }
910
942
 
943
+ obj[property] = value;
944
+
911
945
  set(tracked, value, block);
912
946
  }
913
947
 
@@ -1028,8 +1062,8 @@ export function structured_clone(val, options) {
1028
1062
  if (typeof val === 'object' && val !== null) {
1029
1063
  var tracked_properties = val[TRACKED_OBJECT];
1030
1064
  if (tracked_properties !== undefined) {
1031
- if (is_array(val)) {
1032
- /** @type {RippleArray<any>} */ (val).$length;
1065
+ if (is_ripple_array(val)) {
1066
+ val.$length;
1033
1067
  }
1034
1068
  return structured_clone(object_values(val), options);
1035
1069
  }
@@ -1038,7 +1072,7 @@ export function structured_clone(val, options) {
1038
1072
  }
1039
1073
 
1040
1074
  export function object_keys(obj) {
1041
- if (is_array(obj) && TRACKED_OBJECT in obj) {
1075
+ if (is_ripple_array(obj)) {
1042
1076
  obj.$length;
1043
1077
  }
1044
1078
  return original_object_keys(obj);
@@ -1050,7 +1084,7 @@ export function object_values(obj) {
1050
1084
  if (tracked_properties === undefined) {
1051
1085
  return original_object_values(obj);
1052
1086
  }
1053
- if (is_array(obj)) {
1087
+ if (is_ripple_array(obj)) {
1054
1088
  obj.$length;
1055
1089
  }
1056
1090
  var keys = original_object_keys(obj);
@@ -1069,7 +1103,7 @@ export function object_entries(obj) {
1069
1103
  if (tracked_properties === undefined) {
1070
1104
  return original_object_entries(obj);
1071
1105
  }
1072
- if (is_array(obj)) {
1106
+ if (is_ripple_array(obj)) {
1073
1107
  obj.$length;
1074
1108
  }
1075
1109
  var keys = original_object_keys(obj);
@@ -1169,8 +1203,8 @@ export function pop_component() {
1169
1203
  active_component = component.p;
1170
1204
  }
1171
1205
 
1172
- export function use_prop() {
1173
- return Symbol(USE_PROP);
1206
+ export function ref_prop() {
1207
+ return Symbol(REF_PROP);
1174
1208
  }
1175
1209
 
1176
1210
  /**
@@ -1195,4 +1229,4 @@ export function exclude_from_object(obj, keys) {
1195
1229
  delete obj[key];
1196
1230
  }
1197
1231
  return obj;
1198
- }
1232
+ }
@@ -1,3 +1,5 @@
1
+ import { TRACKED_OBJECT } from './constants.js';
2
+
1
3
  export var get_descriptor = Object.getOwnPropertyDescriptor;
2
4
  export var get_descriptors = Object.getOwnPropertyDescriptors;
3
5
  export var array_from = Array.from;
@@ -15,3 +17,19 @@ export function create_anchor() {
15
17
  t.__t = '';
16
18
  return t;
17
19
  }
20
+
21
+ /**
22
+ * @param {any} obj
23
+ * @returns {boolean}
24
+ */
25
+ export function is_ripple_array(obj) {
26
+ return is_array(obj) && TRACKED_OBJECT in obj && '$length' in obj;
27
+ }
28
+
29
+ /**
30
+ * @param {any} value
31
+ * @returns {boolean}
32
+ */
33
+ export function is_positive_integer(value) {
34
+ return Number.isInteger(value) && /**@type {number} */ (value) >= 0;
35
+ }
@@ -9,6 +9,20 @@ exports[`basic > render semi-dynamic text 1`] = `
9
9
  </div>
10
10
  `;
11
11
 
12
+ exports[`basic > render spread props without duplication 1`] = `
13
+ <div>
14
+ <div>
15
+ <input
16
+ id="vehicle1"
17
+ name="car"
18
+ type="checkbox"
19
+ value="Bike"
20
+ />
21
+ </div>
22
+
23
+ </div>
24
+ `;
25
+
12
26
  exports[`basic > render static attributes 1`] = `
13
27
  <div>
14
28
  <div