-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(binary): add support for passing binary files to signals via ref…
…erences
- Loading branch information
Showing
4 changed files
with
39 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
let referenceRefCount = 0 | ||
const storage = {} | ||
|
||
export default { | ||
push (binary) { | ||
const ref = `binary-ref-${++referenceRefCount}` | ||
storage[ref] = binary | ||
return ref | ||
}, | ||
pop (ref) { | ||
const binary = storage[ref] | ||
delete storage[ref] | ||
return binary | ||
} | ||
} |
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,23 @@ | ||
/* eslint-env mocha */ | ||
import binary from './binary' | ||
import assert from 'assert' | ||
|
||
describe('binary', () => { | ||
it('create new reference on each run', () => { | ||
const obj = {} | ||
const ref1 = binary.push(obj) | ||
const ref2 = binary.push(obj) | ||
assert.ok(ref1 !== ref2) | ||
}) | ||
it('retrieves original element with ref', () => { | ||
const obj = {} | ||
const ref = binary.push(obj) | ||
const objBack = binary.pop(ref) | ||
assert.equal(obj, objBack) | ||
}) | ||
it('removes element on pop', () => { | ||
const ref = binary.push({}) | ||
binary.pop(ref) | ||
assert.equal(undefined, binary.pop(ref)) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export {default as Controller} from './Controller' | ||
export {default as Computed} from './Computed' | ||
export {default as binary} from './binary' |
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