Commit 89d47c21 authored by Aron Carroll's avatar Aron Carroll

Rename CrossFrameBridge to Bridge

parent 72a07437
...@@ -4,7 +4,7 @@ class AnnotationUISync ...@@ -4,7 +4,7 @@ class AnnotationUISync
###* ###*
# @name AnnotationUISync # @name AnnotationUISync
# @param {$window} $window An Angular window service. # @param {$window} $window An Angular window service.
# @param {CrossFrameBridge} bridge # @param {Bridge} bridge
# @param {AnnotationSync} annotationSync # @param {AnnotationSync} annotationSync
# @param {AnnotationUI} annotationUI An instance of the AnnotatonUI service # @param {AnnotationUI} annotationUI An instance of the AnnotatonUI service
# @description # @description
......
...@@ -14,7 +14,7 @@ Bridge = class Annotator.Plugin.Bridge extends Annotator.Plugin ...@@ -14,7 +14,7 @@ Bridge = class Annotator.Plugin.Bridge extends Annotator.Plugin
discovery = new Bridge.CrossFrameDiscovery(window, opts) discovery = new Bridge.CrossFrameDiscovery(window, opts)
opts = extract(options, 'scope') opts = extract(options, 'scope')
bridge = new Bridge.CrossFrameBridge(opts) bridge = new Bridge.Bridge(opts)
opts = extract(options, 'on', 'emit', 'formatter', 'parser') opts = extract(options, 'on', 'emit', 'formatter', 'parser')
annotationSync = new Bridge.AnnotationSync(bridge, opts) annotationSync = new Bridge.AnnotationSync(bridge, opts)
......
class CrossFrameBridge class Bridge
options: options:
# Scope identifier to distinguish this channel from any others # Scope identifier to distinguish this channel from any others
scope: 'crossFrameBridge' scope: 'crossFrameBridge'
...@@ -89,7 +89,7 @@ class CrossFrameBridge ...@@ -89,7 +89,7 @@ class CrossFrameBridge
on: (method, callback) -> on: (method, callback) ->
if @channelListeners[method] if @channelListeners[method]
throw new Error("Listener '#{method}' already bound in CrossFrameBridge") throw new Error("Listener '#{method}' already bound in Bridge")
@channelListeners[method] = callback @channelListeners[method] = callback
for l in @links for l in @links
...@@ -116,6 +116,6 @@ class CrossFrameBridge ...@@ -116,6 +116,6 @@ class CrossFrameBridge
channel = Channel.build(options) channel = Channel.build(options)
if angular? if angular?
angular.module('h').value('CrossFrameBridge', CrossFrameBridge) angular.module('h').value('Bridge', Bridge)
else else
Annotator.Plugin.Bridge.CrossFrameBridge = CrossFrameBridge Annotator.Plugin.Bridge.Bridge = Bridge
...@@ -4,12 +4,12 @@ class CrossFrameService ...@@ -4,12 +4,12 @@ class CrossFrameService
this.inject = [ this.inject = [
'$rootScope', '$document', '$window', 'store', 'annotationUI' '$rootScope', '$document', '$window', 'store', 'annotationUI'
'CrossFrameDiscovery', 'CrossFrameBridge', 'CrossFrameDiscovery', 'Bridge',
'AnnotationSync', 'AnnotationUISync' 'AnnotationSync', 'AnnotationUISync'
] ]
constructor: ( constructor: (
$rootScope, $document, $window, store, annotationUI $rootScope, $document, $window, store, annotationUI
CrossFrameDiscovery, CrossFrameBridge, CrossFrameDiscovery, Bridge,
AnnotationSync, AnnotationUISync AnnotationSync, AnnotationUISync
) -> ) ->
@providers = [] @providers = []
...@@ -24,7 +24,7 @@ class CrossFrameService ...@@ -24,7 +24,7 @@ class CrossFrameService
createBridge = -> createBridge = ->
options = options =
scope: 'annotator:bridge' scope: 'annotator:bridge'
new CrossFrameBridge(options) new Bridge(options)
createAnnotationSync = (bridge) -> createAnnotationSync = (bridge) ->
whitelist = ['target', 'document', 'uri'] whitelist = ['target', 'document', 'uri']
......
...@@ -4,7 +4,7 @@ sinon.assert.expose(assert, prefix: '') ...@@ -4,7 +4,7 @@ sinon.assert.expose(assert, prefix: '')
describe 'Annotator.Plugin.Bridge', -> describe 'Annotator.Plugin.Bridge', ->
Bridge = null Bridge = null
fakeCFDiscovery = null fakeCFDiscovery = null
fakeCFBridge = null fakeBridge = null
fakeAnnotationSync = null fakeAnnotationSync = null
sandbox = sinon.sandbox.create() sandbox = sinon.sandbox.create()
...@@ -20,7 +20,7 @@ describe 'Annotator.Plugin.Bridge', -> ...@@ -20,7 +20,7 @@ describe 'Annotator.Plugin.Bridge', ->
startDiscovery: sandbox.stub() startDiscovery: sandbox.stub()
stopDiscovery: sandbox.stub() stopDiscovery: sandbox.stub()
fakeCFBridge = fakeBridge =
createChannel: sandbox.stub() createChannel: sandbox.stub()
onConnect: sandbox.stub() onConnect: sandbox.stub()
notify: sandbox.stub() notify: sandbox.stub()
...@@ -32,7 +32,7 @@ describe 'Annotator.Plugin.Bridge', -> ...@@ -32,7 +32,7 @@ describe 'Annotator.Plugin.Bridge', ->
Bridge = Annotator.Plugin.Bridge Bridge = Annotator.Plugin.Bridge
sandbox.stub(Bridge, 'AnnotationSync').returns(fakeAnnotationSync) sandbox.stub(Bridge, 'AnnotationSync').returns(fakeAnnotationSync)
sandbox.stub(Bridge, 'CrossFrameDiscovery').returns(fakeCFDiscovery) sandbox.stub(Bridge, 'CrossFrameDiscovery').returns(fakeCFDiscovery)
sandbox.stub(Bridge, 'CrossFrameBridge').returns(fakeCFBridge) sandbox.stub(Bridge, 'Bridge').returns(fakeBridge)
afterEach -> afterEach ->
sandbox.restore() sandbox.restore()
...@@ -48,15 +48,15 @@ describe 'Annotator.Plugin.Bridge', -> ...@@ -48,15 +48,15 @@ describe 'Annotator.Plugin.Bridge', ->
assert.called(Bridge.CrossFrameDiscovery) assert.called(Bridge.CrossFrameDiscovery)
assert.calledWith(Bridge.CrossFrameDiscovery, window, server: true) assert.calledWith(Bridge.CrossFrameDiscovery, window, server: true)
it 'instantiates the CrossFrameBridge component', -> it 'instantiates the Bridge component', ->
createBridge() createBridge()
assert.called(Bridge.CrossFrameBridge) assert.called(Bridge.Bridge)
assert.calledWith(Bridge.CrossFrameDiscovery) assert.calledWith(Bridge.CrossFrameDiscovery)
it 'passes the options along to the bridge', -> it 'passes the options along to the bridge', ->
createBridge(scope: 'myscope') createBridge(scope: 'myscope')
assert.called(Bridge.CrossFrameBridge) assert.called(Bridge.Bridge)
assert.calledWith(Bridge.CrossFrameBridge, scope: 'myscope') assert.calledWith(Bridge.Bridge, scope: 'myscope')
it 'instantiates the AnnotationSync component', -> it 'instantiates the AnnotationSync component', ->
createBridge() createBridge()
...@@ -66,7 +66,7 @@ describe 'Annotator.Plugin.Bridge', -> ...@@ -66,7 +66,7 @@ describe 'Annotator.Plugin.Bridge', ->
formatter = (x) -> x formatter = (x) -> x
createBridge(formatter: formatter) createBridge(formatter: formatter)
assert.called(Bridge.AnnotationSync) assert.called(Bridge.AnnotationSync)
assert.calledWith(Bridge.AnnotationSync, fakeCFBridge, { assert.calledWith(Bridge.AnnotationSync, fakeBridge, {
on: sinon.match.func on: sinon.match.func
emit: sinon.match.func emit: sinon.match.func
formatter: formatter formatter: formatter
...@@ -82,8 +82,8 @@ describe 'Annotator.Plugin.Bridge', -> ...@@ -82,8 +82,8 @@ describe 'Annotator.Plugin.Bridge', ->
bridge = createBridge() bridge = createBridge()
bridge.pluginInit() bridge.pluginInit()
fakeCFDiscovery.startDiscovery.yield('SOURCE', 'ORIGIN', 'TOKEN') fakeCFDiscovery.startDiscovery.yield('SOURCE', 'ORIGIN', 'TOKEN')
assert.called(fakeCFBridge.createChannel) assert.called(fakeBridge.createChannel)
assert.calledWith(fakeCFBridge.createChannel, 'SOURCE', 'ORIGIN', 'TOKEN') assert.calledWith(fakeBridge.createChannel, 'SOURCE', 'ORIGIN', 'TOKEN')
describe '.destroy', -> describe '.destroy', ->
it 'stops the discovery of new frames', -> it 'stops the discovery of new frames', ->
...@@ -101,17 +101,17 @@ describe 'Annotator.Plugin.Bridge', -> ...@@ -101,17 +101,17 @@ describe 'Annotator.Plugin.Bridge', ->
it 'proxies the call to the bridge', -> it 'proxies the call to the bridge', ->
bridge = createBridge() bridge = createBridge()
bridge.on('event', 'arg') bridge.on('event', 'arg')
assert.calledWith(fakeCFBridge.on, 'event', 'arg') assert.calledWith(fakeBridge.on, 'event', 'arg')
describe '.notify', -> describe '.notify', ->
it 'proxies the call to the bridge', -> it 'proxies the call to the bridge', ->
bridge = createBridge() bridge = createBridge()
bridge.notify(method: 'method') bridge.notify(method: 'method')
assert.calledWith(fakeCFBridge.notify, method: 'method') assert.calledWith(fakeBridge.notify, method: 'method')
describe '.onConnect', -> describe '.onConnect', ->
it 'proxies the call to the bridge', -> it 'proxies the call to the bridge', ->
bridge = createBridge() bridge = createBridge()
fn = -> fn = ->
bridge.onConnect(fn) bridge.onConnect(fn)
assert.calledWith(fakeCFBridge.onConnect, fn) assert.calledWith(fakeBridge.onConnect, fn)
assert = chai.assert assert = chai.assert
sinon.assert.expose assert, prefix: null sinon.assert.expose assert, prefix: null
describe 'CrossFrameBridge', -> describe 'Bridge', ->
sandbox = sinon.sandbox.create() sandbox = sinon.sandbox.create()
createBridge = null createBridge = null
createChannel = null createChannel = null
beforeEach module('h') beforeEach module('h')
beforeEach inject (CrossFrameBridge) -> beforeEach inject (Bridge) ->
createBridge = (options) -> createBridge = (options) ->
new CrossFrameBridge(options) new Bridge(options)
createChannel = -> createChannel = ->
call: sandbox.stub() call: sandbox.stub()
......
...@@ -10,7 +10,7 @@ describe 'CrossFrameService', -> ...@@ -10,7 +10,7 @@ describe 'CrossFrameService', ->
fakeStore = null fakeStore = null
fakeAnnotationUI = null fakeAnnotationUI = null
fakeCrossFrameDiscovery = null fakeCrossFrameDiscovery = null
fakeCrossFrameBridge = null fakeBridge = null
fakeAnnotationSync = null fakeAnnotationSync = null
fakeAnnotationUISync = null fakeAnnotationUISync = null
...@@ -22,7 +22,7 @@ describe 'CrossFrameService', -> ...@@ -22,7 +22,7 @@ describe 'CrossFrameService', ->
fakeAnnotationUI = {} fakeAnnotationUI = {}
fakeCrossFrameDiscovery = fakeCrossFrameDiscovery =
startDiscovery: sandbox.stub() startDiscovery: sandbox.stub()
fakeCrossFrameBridge = fakeBridge =
notify: sandbox.stub() notify: sandbox.stub()
createChannel: sandbox.stub() createChannel: sandbox.stub()
onConnect: sandbox.stub() onConnect: sandbox.stub()
...@@ -35,8 +35,8 @@ describe 'CrossFrameService', -> ...@@ -35,8 +35,8 @@ describe 'CrossFrameService', ->
$provide.value('annotationUI', fakeAnnotationUI) $provide.value('annotationUI', fakeAnnotationUI)
$provide.value('CrossFrameDiscovery', $provide.value('CrossFrameDiscovery',
sandbox.stub().returns(fakeCrossFrameDiscovery)) sandbox.stub().returns(fakeCrossFrameDiscovery))
$provide.value('CrossFrameBridge', $provide.value('Bridge',
sandbox.stub().returns(fakeCrossFrameBridge)) sandbox.stub().returns(fakeBridge))
$provide.value('AnnotationSync', $provide.value('AnnotationSync',
sandbox.stub().returns(fakeAnnotationSync)) sandbox.stub().returns(fakeAnnotationSync))
$provide.value('AnnotationUISync', $provide.value('AnnotationUISync',
...@@ -54,13 +54,13 @@ describe 'CrossFrameService', -> ...@@ -54,13 +54,13 @@ describe 'CrossFrameService', ->
it 'creates a new channel when the discovery module finds a frame', -> it 'creates a new channel when the discovery module finds a frame', ->
fakeCrossFrameDiscovery.startDiscovery.yields('source', 'origin', 'token') fakeCrossFrameDiscovery.startDiscovery.yields('source', 'origin', 'token')
crossframe.connect() crossframe.connect()
assert.calledWith(fakeCrossFrameBridge.createChannel, assert.calledWith(fakeBridge.createChannel,
'source', 'origin', 'token') 'source', 'origin', 'token')
it 'queries discovered frames for metadata', -> it 'queries discovered frames for metadata', ->
info = {metadata: link: [{href: 'http://example.com'}]} info = {metadata: link: [{href: 'http://example.com'}]}
channel = {call: sandbox.stub().yieldsTo('success', info)} channel = {call: sandbox.stub().yieldsTo('success', info)}
fakeCrossFrameBridge.onConnect.yields(channel) fakeBridge.onConnect.yields(channel)
crossframe.connect() crossframe.connect()
assert.calledWith(channel.call, { assert.calledWith(channel.call, {
method: 'getDocumentInfo' method: 'getDocumentInfo'
...@@ -70,7 +70,7 @@ describe 'CrossFrameService', -> ...@@ -70,7 +70,7 @@ describe 'CrossFrameService', ->
it 'updates the providers array', -> it 'updates the providers array', ->
info = {metadata: link: [{href: 'http://example.com'}]} info = {metadata: link: [{href: 'http://example.com'}]}
channel = {call: sandbox.stub().yieldsTo('success', info)} channel = {call: sandbox.stub().yieldsTo('success', info)}
fakeCrossFrameBridge.onConnect.yields(channel) fakeBridge.onConnect.yields(channel)
crossframe.connect() crossframe.connect()
assert.deepEqual(crossframe.providers, [ assert.deepEqual(crossframe.providers, [
{channel: channel, entities: ['http://example.com']} {channel: channel, entities: ['http://example.com']}
...@@ -82,5 +82,5 @@ describe 'CrossFrameService', -> ...@@ -82,5 +82,5 @@ describe 'CrossFrameService', ->
message = {method: 'foo', params: 'bar'} message = {method: 'foo', params: 'bar'}
crossframe.connect() # create the bridge. crossframe.connect() # create the bridge.
crossframe.notify(message) crossframe.notify(message)
assert.calledOn(fakeCrossFrameBridge.notify, fakeCrossFrameBridge) assert.calledOn(fakeBridge.notify, fakeBridge)
assert.calledWith(fakeCrossFrameBridge.notify, message) assert.calledWith(fakeBridge.notify, message)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment