Class: Scarpe::WASMDisplayService

Inherits:
Shoes::DisplayService
  • Object
show all
Includes:
Shoes::Log
Defined in:
lib/scarpe/wasm/wasm_local_display.rb

Overview

This is the simplest type of WASM DisplayService. It creates WASM widgets corresponding to Shoes widgets, manages the WASM and its DOM tree, and generally keeps the Shoes/WASM connection working.

This is an in-process WASM-based display service, with all the limitations that entails. Slow handlers will crash, ending this display service will end the process, too many or too large evals can crash the process, etc. Frequently it’s better to use a RelayDisplayService to a second process containing one of these.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWASMDisplayService

This is called before any of the various WASMWidgets are created, to be able to create them and look them up.



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/scarpe/wasm/wasm_local_display.rb', line 34

def initialize
  if WASMDisplayService.instance
    raise "ERROR! This is meant to be a singleton!"
  end

  WASMDisplayService.instance = self

  super()
  log_init("WASM::WASMDisplayService")

  @display_widget_for = {}
end

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



17
18
19
# File 'lib/scarpe/wasm/wasm_local_display.rb', line 17

def instance
  @instance
end

Instance Attribute Details

#appObject (readonly)

app is the Scarpe::WASMApp



27
28
29
# File 'lib/scarpe/wasm/wasm_local_display.rb', line 27

def app
  @app
end

#control_interfaceObject (readonly)

The ControlInterface is used to handle internal events in WASM Scarpe



21
22
23
# File 'lib/scarpe/wasm/wasm_local_display.rb', line 21

def control_interface
  @control_interface
end

#doc_rootObject (readonly)

The DocumentRoot is the top widget of the WASM-side widget tree



24
25
26
# File 'lib/scarpe/wasm/wasm_local_display.rb', line 24

def doc_root
  @doc_root
end

#wranglerObject (readonly)

wrangler is the Scarpe::WebWrangler



30
31
32
# File 'lib/scarpe/wasm/wasm_local_display.rb', line 30

def wrangler
  @wrangler
end

Instance Method Details

#create_display_widget_for(widget_class_name, widget_id, properties) ⇒ WASMWidget

Create a WASM display widget for a specific Shoes widget, and pair it with the linkable ID for this Shoes widget.

Parameters:

  • widget_class_name (String)

    The class name of the Shoes widget, e.g. Shoes::Button

  • widget_id (String)

    the linkable ID for widget events

  • properties (Hash)

    a JSON-serialisable Hash with the widget’s display properties

Returns:



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
# File 'lib/scarpe/wasm/wasm_local_display.rb', line 54

def create_display_widget_for(widget_class_name, widget_id, properties)
  if widget_class_name == "App"
    unless @doc_root
      raise "WASMDocumentRoot is supposed to be created before WASMApp!"
    end

    display_app = Scarpe::WASMApp.new(properties)
    display_app.document_root = @doc_root
    @control_interface = display_app.control_interface
    @control_interface.doc_root = @doc_root
    @app = @control_interface.app
    @wrangler = @control_interface.wrangler

    set_widget_pairing(widget_id, display_app)

    return display_app
  end

  # Create a corresponding display widget
  display_class = Scarpe::WASMWidget.display_class_for(widget_class_name)
  display_widget = display_class.new(properties)
  set_widget_pairing(widget_id, display_widget)

  if widget_class_name == "DocumentRoot"
    # WASMDocumentRoot is created before WASMApp. Mostly doc_root is just like any other widget,
    # but we'll want a reference to it when we create WASMApp.
    @doc_root = display_widget
  end

  display_widget
end

#destroyvoid

This method returns an undefined value.

Destroy the display service and the app. Quit the process (eventually.)



89
90
91
92
# File 'lib/scarpe/wasm/wasm_local_display.rb', line 89

def destroy
  @app.destroy
  WASMDisplayService.instance = nil
end