mobx-keystone
Advanced tools
Comparing version 0.60.1 to 0.60.2
# Change Log | ||
## 0.60.2 | ||
- Added `swap` to array actions. | ||
## 0.60.1 | ||
@@ -4,0 +8,0 @@ |
@@ -16,3 +16,4 @@ export declare const arrayActions: { | ||
unshift: <T_14>(array: T_14[], ...items: T_14[]) => number; | ||
create: <T_15>(data: T_15[]) => T_15[]; | ||
swap: <T_15>(array: T_15[], index1: number, index2: number) => boolean; | ||
create: <T_16>(data: T_16[]) => T_16[]; | ||
}; |
{ | ||
"name": "mobx-keystone", | ||
"version": "0.60.1", | ||
"version": "0.60.2", | ||
"description": "A MobX powered state management solution based on data trees with first class support for Typescript, snapshots, patches and much more", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -88,3 +88,22 @@ import { remove, set } from "mobx" | ||
swap: standaloneAction( | ||
`${namespace}::swap`, | ||
<T>(array: T[], index1: number, index2: number): boolean => { | ||
if (index1 < 0 || index2 < 0 || index1 >= array.length || index2 >= array.length) { | ||
return false | ||
} | ||
if (index2 < index1) { | ||
;[index1, index2] = [index2, index1] | ||
} | ||
// since a same node cannot be in two places at once we will remove | ||
// both then reinsert them | ||
const [v1] = array.splice(index1, 1) | ||
const [v2] = array.splice(index2 - 1, 1) | ||
array.splice(index1, 0, v2) | ||
array.splice(index2, 0, v1) | ||
return true | ||
} | ||
), | ||
create: <T>(data: T[]): T[] => toTreeNode(data), | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4001411
58196