immutable 5.0.0-beta.1 → 5.0.0-beta.3

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 (82) hide show
  1. package/README.md +3 -3
  2. package/dist/immutable.d.ts +29 -134
  3. package/dist/immutable.es.js +5965 -0
  4. package/dist/immutable.js +59 -1
  5. package/dist/immutable.min.js +32 -32
  6. package/package.json +3 -5
  7. package/dist/es/Collection.js +0 -74
  8. package/dist/es/CollectionImpl.js +0 -781
  9. package/dist/es/Hash.js +0 -259
  10. package/dist/es/Immutable.js +0 -73
  11. package/dist/es/Iterator.js +0 -105
  12. package/dist/es/List.js +0 -691
  13. package/dist/es/Map.js +0 -832
  14. package/dist/es/Math.js +0 -44
  15. package/dist/es/Operations.js +0 -952
  16. package/dist/es/OrderedMap.js +0 -194
  17. package/dist/es/OrderedSet.js +0 -90
  18. package/dist/es/PairSorting.js +0 -29
  19. package/dist/es/Range.js +0 -167
  20. package/dist/es/Record.js +0 -290
  21. package/dist/es/Repeat.js +0 -129
  22. package/dist/es/Seq.js +0 -396
  23. package/dist/es/Set.js +0 -277
  24. package/dist/es/Stack.js +0 -259
  25. package/dist/es/TrieUtils.js +0 -115
  26. package/dist/es/fromJS.js +0 -73
  27. package/dist/es/functional/get.js +0 -37
  28. package/dist/es/functional/getIn.js +0 -40
  29. package/dist/es/functional/has.js +0 -34
  30. package/dist/es/functional/hasIn.js +0 -31
  31. package/dist/es/functional/merge.js +0 -136
  32. package/dist/es/functional/remove.js +0 -55
  33. package/dist/es/functional/removeIn.js +0 -31
  34. package/dist/es/functional/set.js +0 -51
  35. package/dist/es/functional/setIn.js +0 -31
  36. package/dist/es/functional/update.js +0 -30
  37. package/dist/es/functional/updateIn.js +0 -93
  38. package/dist/es/is.js +0 -107
  39. package/dist/es/methods/asImmutable.js +0 -28
  40. package/dist/es/methods/asMutable.js +0 -30
  41. package/dist/es/methods/deleteIn.js +0 -30
  42. package/dist/es/methods/getIn.js +0 -30
  43. package/dist/es/methods/hasIn.js +0 -30
  44. package/dist/es/methods/merge.js +0 -78
  45. package/dist/es/methods/mergeDeep.js +0 -40
  46. package/dist/es/methods/mergeDeepIn.js +0 -36
  47. package/dist/es/methods/mergeIn.js +0 -35
  48. package/dist/es/methods/setIn.js +0 -30
  49. package/dist/es/methods/toObject.js +0 -35
  50. package/dist/es/methods/update.js +0 -32
  51. package/dist/es/methods/updateIn.js +0 -30
  52. package/dist/es/methods/wasAltered.js +0 -28
  53. package/dist/es/methods/withMutations.js +0 -30
  54. package/dist/es/package.json.js +0 -26
  55. package/dist/es/predicates/isAssociative.js +0 -31
  56. package/dist/es/predicates/isCollection.js +0 -30
  57. package/dist/es/predicates/isImmutable.js +0 -31
  58. package/dist/es/predicates/isIndexed.js +0 -30
  59. package/dist/es/predicates/isKeyed.js +0 -30
  60. package/dist/es/predicates/isList.js +0 -30
  61. package/dist/es/predicates/isMap.js +0 -30
  62. package/dist/es/predicates/isOrdered.js +0 -30
  63. package/dist/es/predicates/isOrderedMap.js +0 -31
  64. package/dist/es/predicates/isOrderedSet.js +0 -31
  65. package/dist/es/predicates/isRecord.js +0 -30
  66. package/dist/es/predicates/isSeq.js +0 -30
  67. package/dist/es/predicates/isSet.js +0 -30
  68. package/dist/es/predicates/isStack.js +0 -30
  69. package/dist/es/predicates/isValueObject.js +0 -32
  70. package/dist/es/toJS.js +0 -53
  71. package/dist/es/utils/arrCopy.js +0 -34
  72. package/dist/es/utils/assertNotInfinite.js +0 -33
  73. package/dist/es/utils/coerceKeyPath.js +0 -39
  74. package/dist/es/utils/deepEqual.js +0 -98
  75. package/dist/es/utils/hasOwnProperty.js +0 -26
  76. package/dist/es/utils/invariant.js +0 -28
  77. package/dist/es/utils/isArrayLike.js +0 -43
  78. package/dist/es/utils/isDataStructure.js +0 -38
  79. package/dist/es/utils/isPlainObj.js +0 -51
  80. package/dist/es/utils/mixin.js +0 -34
  81. package/dist/es/utils/quoteString.js +0 -32
  82. package/dist/es/utils/shallowCopy.js +0 -40
package/README.md CHANGED
@@ -152,9 +152,9 @@ via relative path to the type definitions at the top of your file.
152
152
 
153
153
  ```js
154
154
  ///<reference path='./node_modules/immutable/dist/immutable.d.ts'/>
155
- import { Map } from 'immutable';
156
- var map1: Map<string, number>;
157
- map1 = Map({ a: 1, b: 2, c: 3 });
155
+ import Immutable from 'immutable';
156
+ var map1: Immutable.Map<string, number>;
157
+ map1 = Immutable.Map({ a: 1, b: 2, c: 3 });
158
158
  var map2 = map1.set('b', 50);
159
159
  map1.get('b'); // 2
160
160
  map2.get('b'); // 50
@@ -91,6 +91,16 @@
91
91
  */
92
92
 
93
93
  declare namespace Immutable {
94
+ /** @ignore */
95
+ type OnlyObject<T> = Extract<T, object>;
96
+
97
+ /** @ignore */
98
+ type ContainObject<T> = OnlyObject<T> extends object
99
+ ? OnlyObject<T> extends never
100
+ ? false
101
+ : true
102
+ : false;
103
+
94
104
  /**
95
105
  * @ignore
96
106
  *
@@ -100,19 +110,14 @@ declare namespace Immutable {
100
110
  export type DeepCopy<T> = T extends Record<infer R>
101
111
  ? // convert Record to DeepCopy plain JS object
102
112
  {
103
- [key in keyof R]: DeepCopy<R[key]>;
104
- }
105
- : T extends MapOf<infer R>
106
- ? // convert MapOf to DeepCopy plain JS object
107
- {
108
- [key in keyof R]: DeepCopy<R[key]>;
113
+ [key in keyof R]: ContainObject<R[key]> extends true ? unknown : R[key];
109
114
  }
110
115
  : T extends Collection.Keyed<infer KeyedKey, infer V>
111
116
  ? // convert KeyedCollection to DeepCopy plain JS object
112
117
  {
113
118
  [key in KeyedKey extends string | number | symbol
114
119
  ? KeyedKey
115
- : string]: DeepCopy<V>;
120
+ : string]: V extends object ? unknown : V;
116
121
  }
117
122
  : // convert IndexedCollection or Immutable.Set to DeepCopy plain JS array
118
123
  T extends Collection<infer _, infer V>
@@ -123,7 +128,9 @@ declare namespace Immutable {
123
128
  ? Array<DeepCopy<V>>
124
129
  : T extends object // plain JS object are converted deeply
125
130
  ? {
126
- [ObjectKey in keyof T]: DeepCopy<T[ObjectKey]>;
131
+ [ObjectKey in keyof T]: ContainObject<T[ObjectKey]> extends true
132
+ ? unknown
133
+ : T[ObjectKey];
127
134
  }
128
135
  : // other case : should be kept as is
129
136
  T;
@@ -834,96 +841,9 @@ declare namespace Immutable {
834
841
  * not altered.
835
842
  */
836
843
  function Map<K, V>(collection?: Iterable<[K, V]>): Map<K, V>;
837
- function Map<R extends { [key in string | number | symbol]: unknown }>(
838
- obj: R
839
- ): MapOf<R>;
840
844
  function Map<V>(obj: { [key: string]: V }): Map<string, V>;
841
845
  function Map<K extends string | symbol, V>(obj: { [P in K]?: V }): Map<K, V>;
842
846
 
843
- /**
844
- * Represent a Map constructed by an object
845
- *
846
- * @ignore
847
- */
848
- interface MapOf<R extends { [key in string | number | symbol]: unknown }>
849
- extends Map<keyof R, R[keyof R]> {
850
- /**
851
- * Returns the value associated with the provided key, or notSetValue if
852
- * the Collection does not contain this key.
853
- *
854
- * Note: it is possible a key may be associated with an `undefined` value,
855
- * so if `notSetValue` is not provided and this method returns `undefined`,
856
- * that does not guarantee the key was not found.
857
- */
858
- get<K extends keyof R>(key: K, notSetValue?: unknown): R[K];
859
- get<NSV>(key: any, notSetValue: NSV): NSV;
860
-
861
- // https://github.com/microsoft/TypeScript/pull/39094
862
- getIn<P extends ReadonlyArray<string | number | symbol>>(
863
- searchKeyPath: [...P],
864
- notSetValue?: unknown
865
- ): RetrievePath<R, P>;
866
-
867
- set<K extends keyof R>(key: K, value: R[K]): this;
868
-
869
- update(updater: (value: this) => this): this;
870
- update<K extends keyof R>(key: K, updater: (value: R[K]) => R[K]): this;
871
- update<K extends keyof R, NSV extends R[K]>(
872
- key: K,
873
- notSetValue: NSV,
874
- updater: (value: R[K]) => R[K]
875
- ): this;
876
-
877
- // Possible best type is MapOf<Omit<R, K>> but Omit seems to broke other function calls
878
- // and generate recursion error with other methods (update, merge, etc.) until those functions are defined in MapOf
879
- delete<K extends keyof R>(
880
- key: K
881
- ): Extract<R[K], undefined> extends never ? never : this;
882
- remove<K extends keyof R>(
883
- key: K
884
- ): Extract<R[K], undefined> extends never ? never : this;
885
-
886
- toJS(): { [K in keyof R]: DeepCopy<R[K]> };
887
-
888
- toJSON(): { [K in keyof R]: R[K] };
889
- }
890
-
891
- // Loosely based off of this work.
892
- // https://github.com/immutable-js/immutable-js/issues/1462#issuecomment-584123268
893
-
894
- /** @ignore */
895
- type GetMapType<S> = S extends MapOf<infer T> ? T : S;
896
-
897
- /** @ignore */
898
- type Head<T extends ReadonlyArray<any>> = T extends [
899
- infer H,
900
- ...Array<unknown>
901
- ]
902
- ? H
903
- : never;
904
-
905
- /** @ignore */
906
- type Tail<T extends ReadonlyArray<any>> = T extends [unknown, ...infer I]
907
- ? I
908
- : Array<never>;
909
-
910
- /** @ignore */
911
- type RetrievePathReducer<
912
- T,
913
- C,
914
- L extends ReadonlyArray<any>
915
- > = C extends keyof GetMapType<T>
916
- ? L extends []
917
- ? GetMapType<T>[C]
918
- : RetrievePathReducer<GetMapType<T>[C], Head<L>, Tail<L>>
919
- : never;
920
-
921
- /** @ignore */
922
- type RetrievePath<
923
- R,
924
- P extends ReadonlyArray<string | number | symbol>
925
- > = P extends [] ? P : RetrievePathReducer<R, Head<P>, Tail<P>>;
926
-
927
847
  interface Map<K, V> extends Collection.Keyed<K, V> {
928
848
  /**
929
849
  * The number of entries in this Map.
@@ -1141,17 +1061,16 @@ declare namespace Immutable {
1141
1061
  */
1142
1062
  merge<KC, VC>(
1143
1063
  ...collections: Array<Iterable<[KC, VC]>>
1144
- ): Map<K | KC, Exclude<V, VC> | VC>;
1064
+ ): Map<K | KC, V | VC>;
1145
1065
  merge<C>(
1146
1066
  ...collections: Array<{ [key: string]: C }>
1147
- ): Map<K | string, Exclude<V, C> | C>;
1148
-
1067
+ ): Map<K | string, V | C>;
1149
1068
  concat<KC, VC>(
1150
1069
  ...collections: Array<Iterable<[KC, VC]>>
1151
- ): Map<K | KC, Exclude<V, VC> | VC>;
1070
+ ): Map<K | KC, V | VC>;
1152
1071
  concat<C>(
1153
1072
  ...collections: Array<{ [key: string]: C }>
1154
- ): Map<K | string, Exclude<V, C> | C>;
1073
+ ): Map<K | string, V | C>;
1155
1074
 
1156
1075
  /**
1157
1076
  * Like `merge()`, `mergeWith()` returns a new Map resulting from merging
@@ -1171,14 +1090,10 @@ declare namespace Immutable {
1171
1090
  *
1172
1091
  * Note: `mergeWith` can be used in `withMutations`.
1173
1092
  */
1174
- mergeWith<KC, VC, VCC>(
1175
- merger: (oldVal: V, newVal: VC, key: K) => VCC,
1176
- ...collections: Array<Iterable<[KC, VC]>>
1177
- ): Map<K | KC, V | VC | VCC>;
1178
- mergeWith<C, CC>(
1179
- merger: (oldVal: V, newVal: C, key: string) => CC,
1180
- ...collections: Array<{ [key: string]: C }>
1181
- ): Map<K | string, V | C | CC>;
1093
+ mergeWith(
1094
+ merger: (oldVal: V, newVal: V, key: K) => V,
1095
+ ...collections: Array<Iterable<[K, V]> | { [key: string]: V }>
1096
+ ): this;
1182
1097
 
1183
1098
  /**
1184
1099
  * Like `merge()`, but when two compatible collections are encountered with
@@ -1209,12 +1124,9 @@ declare namespace Immutable {
1209
1124
  *
1210
1125
  * Note: `mergeDeep` can be used in `withMutations`.
1211
1126
  */
1212
- mergeDeep<KC, VC>(
1213
- ...collections: Array<Iterable<[KC, VC]>>
1214
- ): Map<K | KC, V | VC>;
1215
- mergeDeep<C>(
1216
- ...collections: Array<{ [key: string]: C }>
1217
- ): Map<K | string, V | C>;
1127
+ mergeDeep(
1128
+ ...collections: Array<Iterable<[K, V]> | { [key: string]: V }>
1129
+ ): this;
1218
1130
 
1219
1131
  /**
1220
1132
  * Like `mergeDeep()`, but when two non-collections or incompatible
@@ -1682,31 +1594,14 @@ declare namespace Immutable {
1682
1594
  */
1683
1595
  merge<KC, VC>(
1684
1596
  ...collections: Array<Iterable<[KC, VC]>>
1685
- ): OrderedMap<K | KC, Exclude<V, VC> | VC>;
1597
+ ): OrderedMap<K | KC, V | VC>;
1686
1598
  merge<C>(
1687
1599
  ...collections: Array<{ [key: string]: C }>
1688
- ): OrderedMap<K | string, Exclude<V, C> | C>;
1689
-
1600
+ ): OrderedMap<K | string, V | C>;
1690
1601
  concat<KC, VC>(
1691
1602
  ...collections: Array<Iterable<[KC, VC]>>
1692
- ): OrderedMap<K | KC, Exclude<V, VC> | VC>;
1693
- concat<C>(
1694
- ...collections: Array<{ [key: string]: C }>
1695
- ): OrderedMap<K | string, Exclude<V, C> | C>;
1696
-
1697
- mergeWith<KC, VC, VCC>(
1698
- merger: (oldVal: V, newVal: VC, key: K) => VCC,
1699
- ...collections: Array<Iterable<[KC, VC]>>
1700
- ): OrderedMap<K | KC, V | VC | VCC>;
1701
- mergeWith<C, CC>(
1702
- merger: (oldVal: V, newVal: C, key: string) => CC,
1703
- ...collections: Array<{ [key: string]: C }>
1704
- ): OrderedMap<K | string, V | C | CC>;
1705
-
1706
- mergeDeep<KC, VC>(
1707
- ...collections: Array<Iterable<[KC, VC]>>
1708
1603
  ): OrderedMap<K | KC, V | VC>;
1709
- mergeDeep<C>(
1604
+ concat<C>(
1710
1605
  ...collections: Array<{ [key: string]: C }>
1711
1606
  ): OrderedMap<K | string, V | C>;
1712
1607