-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cozy-realtime): Add cozy-client plugin
- Loading branch information
Cyrille Perois
committed
Jan 2, 2020
1 parent
248fac7
commit 820d663
Showing
5 changed files
with
94 additions
and
0 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 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,43 @@ | ||
import CozyRealtime from './CozyRealtime' | ||
|
||
/** | ||
* Realtime plugin for cozy-client | ||
* | ||
* @class | ||
*/ | ||
class RealtimePlugin { | ||
/** | ||
* Constructor of RealtimePlugin | ||
* | ||
* @constructor | ||
* @param {CozyClient} client A cozy-client instance | ||
*/ | ||
constructor(client) { | ||
this.realtime = new CozyRealtime({ client }) | ||
} | ||
|
||
/** | ||
* @see CozyRealtime.subscribe | ||
*/ | ||
subscribe(...args) { | ||
this.realtime.subscribe(...args) | ||
} | ||
|
||
/** | ||
* @see CozyRealtime.unsubscribe | ||
*/ | ||
unsubscribe(...args) { | ||
this.realtime.unsubscribe(...args) | ||
} | ||
|
||
/** | ||
* @see CozyRealtime.unsubscribeAll | ||
*/ | ||
unsubscribeAll() { | ||
this.realtime.unsubscribeAll() | ||
} | ||
} | ||
|
||
RealtimePlugin.pluginName = 'realtime' | ||
|
||
export default RealtimePlugin |
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,24 @@ | ||
import RealtimePlugin from './RealtimePlugin' | ||
import CozyClient from 'cozy-client' | ||
|
||
let client | ||
|
||
beforeEach(() => { | ||
client = new CozyClient({ | ||
uri: 'http://cozy.tools:8080', | ||
token: 'fake-token' | ||
}) | ||
}) | ||
|
||
it('should attach to the client under the `realtime` plugin name', () => { | ||
expect(client.plugins.realtime).toBeUndefined() | ||
client.registerPlugin(RealtimePlugin) | ||
expect(client.plugins.realtime).toBeInstanceOf(RealtimePlugin) | ||
}) | ||
|
||
it('should expose the same API as CozyRealtime', () => { | ||
client.registerPlugin(RealtimePlugin) | ||
expect(client.plugins.realtime.subscribe).toBeInstanceOf(Function) | ||
expect(client.plugins.realtime.unsubscribe).toBeInstanceOf(Function) | ||
expect(client.plugins.realtime.unsubscribeAll).toBeInstanceOf(Function) | ||
}) |
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,3 +1,4 @@ | ||
import CozyRealtime from './CozyRealtime' | ||
|
||
export { default as RealtimePlugin } from './RealtimePlugin' | ||
export default CozyRealtime |
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