Clean up libraries

The following were done
- Remove unused imports and console.logs.
- Fix parameters after testing.
This commit is contained in:
Angelico
2020-01-15 16:29:52 +08:00
parent 70f06dcd42
commit be64fcab47
2 changed files with 25 additions and 15 deletions

View File

@@ -2,10 +2,11 @@ import { Socket } from 'phoenix-channels'
import BaseRequest from './BaseRequest'
class Base {
constructor(tableName, restUrl, apiSocket, uuid) {
constructor(tableName, restUrl, apiSocket, schema, uuid) {
this.tableName = tableName
this.restUrl = restUrl
this.apiSocket = apiSocket
this.schema = schema
this.uuid = uuid
this.socket = null
@@ -16,8 +17,15 @@ class Base {
}
createListener() {
this.socket = new Socket(apiSocket)
this.channel = this.socket.channel(this.tableName)
this.socket = new Socket(this.apiSocket)
this.channel = this.socket.channel(`realtime:${this.schema}:${this.tableName}`)
this.socket.onOpen(() => {
console.log('Socket connected')
})
this.socket.onClose(() => {
console.log('Socket disconnected')
})
}
on(eventType, callbackFunction) {
@@ -25,6 +33,8 @@ class Base {
var ref = this.channel.on(eventType, callbackFunction)
this.listeners[eventType] = ref
return this
}
subscribe() {
@@ -39,15 +49,14 @@ class Base {
.receive('error', resp => console.log('Unable to join ', resp))
.receive('timeout', () => console.log('Networking issue. Still waiting...'))
}
return this
}
unsubscribe() {
for (var ref in this.listeners) {
let eventName = this.listeners[ref]
this.off(eventName, ref)
}
this.socket.disconnect()
return this
}
request(method) {

View File

@@ -1,5 +1,3 @@
import BaseRequest from './BaseRequest'
import Subscription from './Subscription'
import { uuid } from './utils/Helpers'
import Base from './Base'
@@ -10,6 +8,7 @@ class SupabaseClient {
this.restUrl = null
this.apiSocket = null
this.schema = null
this.subscriptions = {}
this.authenticate(supabaseUrl, supabaseKey)
@@ -17,19 +16,21 @@ class SupabaseClient {
authenticate(supabaseUrl, supabaseKey){
// do something to utilise parameters and receive
// the restUrl & apiSocket
// the restUrl, apiSocket and schema
var restUrl = supabaseUrl
var restUrl = ''
var apiSocket = ''
var schema = ''
this.restUrl = restUrl
this.apiSocket = apiSocket
this.restUrl = 'http://localhost:3000'
this.apiSocket = 'ws://localhost:4000/socket'
this.schema = 'public'
}
from(tableName){
let identifier = uuid()
this.subscriptions[identifier] = new Base(tableName, this.restUrl, this.apiSocket, identifier)
this.subscriptions[identifier] = new Base(tableName, this.restUrl, this.apiSocket, this.schema, identifier)
return this.subscriptions[identifier]
}