Skip to content

Commit

Permalink
feat(binary): add support for passing binary files to signals via ref…
Browse files Browse the repository at this point in the history
…erences
  • Loading branch information
gaspard committed Nov 29, 2016
1 parent 3363217 commit be1abb2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/cerebral/src/binary.js
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
}
}
23 changes: 23 additions & 0 deletions packages/cerebral/src/binary.test.js
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))
})
})
1 change: 1 addition & 0 deletions packages/cerebral/src/index.js
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'
1 change: 0 additions & 1 deletion packages/cerebral/src/operators/debounce.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ describe('operator.debounce', () => {
[ debounce(50), {
continue: [
() => {
console.log(result)
assert.deepEqual(result, ['parallel', 'parallel', 'discard'])
done()
}
Expand Down

0 comments on commit be1abb2

Please sign in to comment.