Skip to content

Commit

Permalink
Add export JS component and improve some error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tatut committed Jan 13, 2024
1 parent 722502e commit 441e910
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/LiveWeb-Bulma/LWBulmaColumns.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ LWBulmaColumns >> oneQuarter: aComponent [
LWBulmaColumns >> renderOn: h [
h div: { #class -> 'columns' } with: [
columns do: [ :c |
h div: { #class -> ('column {1}' format: {c value}) } with: [ c key render ]
h div: { #class -> ('column {1}' format: {c value}) } with: [ c key render: h ]
]
]
]
Expand Down
34 changes: 34 additions & 0 deletions src/LiveWeb-Core/LWExportJS.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Class {
#name : #LWExportJS,
#superclass : #LWComponent,
#instVars : [
'export'
],
#category : #'LiveWeb-Core'
}

{ #category : #accessing }
LWExportJS >> export: nameToCallbackAssociation [
export add: nameToCallbackAssociation.
]

{ #category : #initialization }
LWExportJS >> initialize [
super initialize.
export := OrderedCollection new.
]

{ #category : #rendering }
LWExportJS >> renderOn: h [
h script: [
export do: [ :e |
| name cb cbId argNames |
name := e key.
cb := e value.
argNames := ',' join: ((1 to: cb numArgs) collect: [ :i | 'a{1}' format: { i } ]).
cbId := ctx registerCallback: cb for: self.
h raw: 'function '; raw: name asString; raw: '('; raw: argNames;
raw: '){_lws('; raw: cbId asString; raw: ',['; raw: argNames; raw: '])} '.
]
]
]
11 changes: 10 additions & 1 deletion src/LiveWeb-Core/LWPageConnection.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ LWPageConnection >> run: aWebSocket [

[ ws runWith: [ :msg |
LWLogEvent debug: '<- ', msg printString.
self callback: msg ]]
self tryCallback: msg ]]
on: ConnectionClosed
do: [
LWLogEvent debug: 'Page disconnected, id: ', page id asString.
Expand All @@ -118,3 +118,12 @@ LWPageConnection >> run: aWebSocket [
LWPageConnection >> send: patches [
ws sendMessage: (STONJSON toString: patches)
]

{ #category : #'as yet unclassified' }
LWPageConnection >> tryCallback: message [
[ self callback: message ]
on: Error
do: [ :ex |
LWLogEvent error: 'Error in callback processing: ', ex asString
]
]

0 comments on commit 441e910

Please sign in to comment.