all files / collab/ CollabServerConfigurator.js

0% Statements 0/16
0% Branches 0/4
0% Functions 0/13
0% Lines 0/16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92                                                                                                                                                                                       
import DocumentEngine from './DocumentEngine'
 
class CollabServerConfigurator {
  constructor() {
    this.config = {
      heartbeat: 30*1000,
      documentStore: undefined,
      changeStore: undefined,
      snapshotStore: undefined
    }
  }
 
  setHost(host) {
    this.config.host = host
  }
 
  setPort(port) {
    this.config.port = port
  }
 
  // Record phase API
  // ------------------------
 
  setDocumentStore(documentStore) {
    this.config.documentStore = documentStore
  }
 
  setChangeStore(changeStore) {
    this.config.changeStore = changeStore
  }
 
  setSnapshotStore(snapshotStore) {
    this.config.snapshotStore = snapshotStore
  }
 
  // Config Interpreter API
  // ------------------------
 
  getHost() {
    return this.config.host
  }
 
  getPort() {
    return this.config.port
  }
 
  getDocumentStore() {
    return this.config.documentStore
  }
 
  getChangeStore() {
    return this.config.changeStore
  }
 
  getSnapshotStore() {
    return this.config.snapshotStore
  }
 
  /*
    TODO: We should discuss if it is a good idea that the configurator 'owns'
    instances. Don't see a better solution for now though.
  */
  getDocumentEngine() {
    if (!this.documentEngine) {
      this.documentEngine = new DocumentEngine({
        documentStore: this.config.documentStore,
        changeStore: this.config.changeStore,
        snapshotStore: this.config.snapshotStore
      })
    }
    return this.documentEngine
  }
 
  /**
    Configure this instance of configuration for provided package.
    @param  {Object} pkg     Object should contain a `configure` method that
                             takes a Configurator instance as the first method.
    @param  {Object} options Additional options to pass to the
                             package.`configure` method
 
    @return {configurator}   returns the configurator instance to make it easy
                             to chain calls to import.
   */
  import(pkg, options) {
    pkg.configure(this, options || {})
    return this
  }
 
}
 
export default CollabServerConfigurator