Revision 0.27.1

This commit is contained in:
sinclair
2023-04-10 20:27:53 +09:00
parent 5454181f14
commit 691c24b845
3 changed files with 16 additions and 16 deletions

View File

@@ -2,4 +2,4 @@
## Updates
- Adds a `Value.Mutate(current, next): void` function. This function performs a deep mutable assignment on a value by internally remapping the `next(right)` values on the `current(left)`. Values omitted on the right will also be deleted on the left. This function can be useful instances where mutation of data is required without modification to existing references. An example of which might be React which tracks reference values to signal redraws. This function is implemented by way of `ValuePointer`.
- Adds a `Value.Mutate(left, right)` function. This function performs a deep mutable assignment on a value by internally remapping the `right` values on the `left`. Values omitted on the right will also be deleted on the left. This function can be useful scenarios where mutation of data is required without replacing existing reference values. An example of which might be React which tracks reference values to indicate redraw. This function is implemented by way of `ValuePointer`.

View File

@@ -1 +1 @@
import './mutate'
import './mutate'

View File

@@ -29,58 +29,58 @@ describe('value/mutate/Mutate', () => {
// Mutate
// --------------------------------------------
it('Should mutate 0', () => {
const Y = { z: 1 }
const Y = { z: 1 }
const X = { y: Y }
const A = { x: X }
const A = { x: X }
Value.Mutate(A, {})
Assert.deepEqual(A, {})
})
it('Should mutate 1', () => {
const Y = { z: 1 }
const Y = { z: 1 }
const X = { y: Y }
const A = { x: X }
const A = { x: X }
Value.Mutate(A, { x: { y: { z: 2 } } })
Assert.equal(A.x.y.z, 2)
Assert.equal(A.x.y, Y)
Assert.equal(A.x, X)
})
it('Should mutate 2', () => {
const Y = { z: 1 }
const Y = { z: 1 }
const X = { y: Y }
const A = { x: X }
const A = { x: X }
Value.Mutate(A, { x: { y: { z: [1, 2, 3] } } })
Assert.deepEqual(A.x.y.z, [1, 2, 3])
Assert.equal(A.x.y, Y)
Assert.equal(A.x, X)
})
it('Should mutate 3', () => {
const Y = { z: 1 }
const Y = { z: 1 }
const X = { y: Y }
const A = { x: X }
const A = { x: X }
Value.Mutate(A, { x: {} })
Assert.equal(A.x.y, undefined)
Assert.equal(A.x, X)
})
it('Should mutate 4', () => {
const Y = { z: 1 }
const Y = { z: 1 }
const X = { y: Y }
const A = { x: X }
const A = { x: X }
Value.Mutate(A, { x: { y: 1 } })
Assert.equal(A.x.y, 1)
Assert.equal(A.x, X)
})
it('Should mutate 5', () => {
const Y = { z: 1 }
const Y = { z: 1 }
const X = { y: Y }
const A = { x: X }
const A = { x: X }
Value.Mutate(A, { x: { y: [1, 2, 3] } })
Assert.deepEqual(A.x.y, [1, 2, 3])
Assert.equal(A.x, X)
})
it('Should mutate 6', () => {
const Y = { z: 1 }
const Y = { z: 1 }
const X = { y: Y }
const A = { x: X }
const A = { x: X }
Value.Mutate(A, { x: [1, 2, 3] })
Assert.notEqual(A.x, X)
Assert.deepEqual(A.x, [1, 2, 3])