-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(TypedArrays): add reactivity support for typed arrays
- Loading branch information
1 parent
48cb553
commit aaa212a
Showing
6 changed files
with
96 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { expect } from 'chai' | ||
import { observable, isObservable } from '@nx-js/observer-util' | ||
|
||
describe('none observable built-ins', () => { | ||
it('objects with global constructors should not be converted to observables', () => { | ||
window.MyClass = class MyClass {} | ||
const obj = new window.MyClass() | ||
const obs = observable(obj) | ||
expect(obs).to.equal(obj) | ||
expect(isObservable(obs)).to.equal(false) | ||
}) | ||
|
||
it('objects with local constructors should be converted to observables', () => { | ||
class MyClass {} | ||
const obj = new MyClass() | ||
const obs = observable(obj) | ||
expect(obs).to.not.equal(obj) | ||
expect(isObservable(obs)).to.equal(true) | ||
}) | ||
|
||
it('global objects should be converted to observables', () => { | ||
window.obj = {} | ||
const obs = observable(window.obj) | ||
expect(obs).to.not.equal(window.obj) | ||
expect(isObservable(obs)).to.equal(true) | ||
}) | ||
|
||
it('Date should not be converted to observable', () => { | ||
const date = new Date() | ||
const obsDate = observable(date) | ||
expect(obsDate).to.equal(date) | ||
expect(isObservable(obsDate)).to.equal(false) | ||
}) | ||
|
||
it('RegExp should not be converted to observable', () => { | ||
const regex = new RegExp() | ||
const obsRegex = observable(regex) | ||
expect(obsRegex).to.equal(regex) | ||
expect(isObservable(obsRegex)).to.equal(false) | ||
}) | ||
|
||
it('Node should not be converted to observable', () => { | ||
const node = document | ||
const obsNode = observable(node) | ||
expect(obsNode).to.equal(node) | ||
expect(isObservable(obsNode)).to.equal(false) | ||
}) | ||
|
||
it('WebAudio should not be converted to observable', () => { | ||
const audio = new AudioContext() | ||
const obsAudio = observable(audio) | ||
expect(obsAudio).to.equal(audio) | ||
expect(isObservable(obsAudio)).to.equal(false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { expect } from 'chai' | ||
import { observable, isObservable, observe } from '@nx-js/observer-util' | ||
|
||
const TypedArrays = [ | ||
Int8Array, | ||
Uint8Array, | ||
Uint8ClampedArray, | ||
Int16Array, | ||
Uint16Array, | ||
Int32Array, | ||
Uint32Array, | ||
Float32Array, | ||
Float64Array | ||
] | ||
|
||
describe('typed arrays', () => { | ||
for (const TypedArray of TypedArrays) { | ||
it(`${TypedArray.name} should observe mutations`, () => { | ||
let dummy | ||
const array = observable(new TypedArray(2)) | ||
expect(isObservable(array)).to.equal(true) | ||
|
||
observe(() => (dummy = array[0])) | ||
|
||
expect(dummy).to.equal(0) | ||
array[0] = 12 | ||
expect(dummy).to.equal(12) | ||
}) | ||
} | ||
}) |