module Collab::JS

Public Class Methods

apply_commit(document, commit, pos: nil, map_steps_through:, schema_name:) click to toggle source
# File lib/collab/js.rb, line 30
def apply_commit(document, commit, pos: nil, map_steps_through:, schema_name:)
  call("applyCommit", {doc: document, commit: commit, mapStepsThrough: map_steps_through, pos: pos},schema_name)
end
call(name, data = nil, schema_name = nil) click to toggle source
# File lib/collab/js.rb, line 24
def call(name, data = nil, schema_name = nil)
  req = {name: name, data: data, schemaPackage: ::Collab.config.schema_package}
  req[:schemaName] = schema_name if schema_name
  with_js { |js| js.call(JSON.generate(req)) }
end
document_to_html(document, schema_name:) click to toggle source
# File lib/collab/js.rb, line 38
def document_to_html(document, schema_name:)
  call("docToHtml", document, schema_name)
end
html_to_document(html, schema_name:) click to toggle source
# File lib/collab/js.rb, line 34
def html_to_document(html, schema_name:)
  call("htmlToDoc", html, schema_name)
end
map_through(steps:, pos:) click to toggle source
# File lib/collab/js.rb, line 42
def map_through(steps:, pos:)
  call("mapThru", {steps: steps, pos: pos})
end
queue() click to toggle source
# File lib/collab/js.rb, line 10
def queue
  initialize_queue unless @queue_initialized
  @queue
end
with_js() { |js| ... } click to toggle source

Calls the block given with a JS process acquired from the queue Will block until a JS process is available

# File lib/collab/js.rb, line 17
def with_js
  js = queue.pop
  yield js
ensure
  queue << js
end

Private Class Methods

initialize_queue() click to toggle source

Thread-safe initialization of the NodeJS process queue

# File lib/collab/js.rb, line 48
def initialize_queue
  @queue_initialization_mutex.synchronize do
    unless @queue_initialized
      ::Collab.config.num_js_processes.times { @queue << ::Collab::JS::JSProcess.new }
      @queue_initialized = true
    end
  end
end