forked from mbk-lab/rui_orig
Communication optimisation
This commit is contained in:
parent
392a0a0288
commit
5e532a000f
10
animation.go
10
animation.go
|
@ -607,8 +607,12 @@ func (view *viewData) SetAnimated(tag string, value interface{}, animation Anima
|
||||||
return view.Set(tag, value)
|
return view.Set(tag, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateProperty(view.htmlID(), "ontransitionend", "transitionEndEvent(this, event)", view.session)
|
session := view.Session()
|
||||||
updateProperty(view.htmlID(), "ontransitioncancel", "transitionCancelEvent(this, event)", view.session)
|
htmlID := view.htmlID()
|
||||||
|
session.startUpdateScript(htmlID)
|
||||||
|
|
||||||
|
updateProperty(htmlID, "ontransitionend", "transitionEndEvent(this, event)", view.session)
|
||||||
|
updateProperty(htmlID, "ontransitioncancel", "transitionCancelEvent(this, event)", view.session)
|
||||||
|
|
||||||
if prevAnimation, ok := view.transitions[tag]; ok {
|
if prevAnimation, ok := view.transitions[tag]; ok {
|
||||||
view.singleTransition[tag] = prevAnimation
|
view.singleTransition[tag] = prevAnimation
|
||||||
|
@ -618,6 +622,8 @@ func (view *viewData) SetAnimated(tag string, value interface{}, animation Anima
|
||||||
view.transitions[tag] = animation
|
view.transitions[tag] = animation
|
||||||
view.updateTransitionCSS()
|
view.updateTransitionCSS()
|
||||||
|
|
||||||
|
session.finishUpdateScript(htmlID)
|
||||||
|
|
||||||
result := view.Set(tag, value)
|
result := view.Set(tag, value)
|
||||||
if !result {
|
if !result {
|
||||||
delete(view.singleTransition, tag)
|
delete(view.singleTransition, tag)
|
||||||
|
|
|
@ -231,7 +231,7 @@ function updateProperty(elementId, property, value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeProperty(elementId, property, value) {
|
function removeProperty(elementId, property) {
|
||||||
var element = document.getElementById(elementId);
|
var element = document.getElementById(elementId);
|
||||||
if (element && element.hasAttribute(property)) {
|
if (element && element.hasAttribute(property)) {
|
||||||
element.removeAttribute(property);
|
element.removeAttribute(property);
|
||||||
|
|
|
@ -104,6 +104,10 @@ type Session interface {
|
||||||
|
|
||||||
popupManager() *popupManager
|
popupManager() *popupManager
|
||||||
imageManager() *imageManager
|
imageManager() *imageManager
|
||||||
|
|
||||||
|
startUpdateScript(htmlID string)
|
||||||
|
updateScript(htmlID string) *strings.Builder
|
||||||
|
finishUpdateScript(htmlID string)
|
||||||
}
|
}
|
||||||
|
|
||||||
type sessionData struct {
|
type sessionData struct {
|
||||||
|
@ -134,6 +138,7 @@ type sessionData struct {
|
||||||
events chan DataObject
|
events chan DataObject
|
||||||
animationCounter int
|
animationCounter int
|
||||||
animationCSS string
|
animationCSS string
|
||||||
|
updateScripts map[string]*strings.Builder
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSession(app Application, id int, customTheme string, params DataObject) Session {
|
func newSession(app Application, id int, customTheme string, params DataObject) Session {
|
||||||
|
@ -149,6 +154,7 @@ func newSession(app Application, id int, customTheme string, params DataObject)
|
||||||
session.ignoreUpdates = false
|
session.ignoreUpdates = false
|
||||||
session.animationCounter = 0
|
session.animationCounter = 0
|
||||||
session.animationCSS = ""
|
session.animationCSS = ""
|
||||||
|
session.updateScripts = map[string]*strings.Builder{}
|
||||||
|
|
||||||
if customTheme != "" {
|
if customTheme != "" {
|
||||||
if theme, ok := CreateThemeFromText(customTheme); ok {
|
if theme, ok := CreateThemeFromText(customTheme); ok {
|
||||||
|
|
|
@ -2,8 +2,33 @@ package rui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (session *sessionData) startUpdateScript(htmlID string) {
|
||||||
|
buffer := allocStringBuilder()
|
||||||
|
session.updateScripts[htmlID] = buffer
|
||||||
|
buffer.WriteString("var element = document.getElementById('")
|
||||||
|
buffer.WriteString(htmlID)
|
||||||
|
buffer.WriteString("');\nif (element) {\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (session *sessionData) updateScript(htmlID string) *strings.Builder {
|
||||||
|
if buffer, ok := session.updateScripts[htmlID]; ok {
|
||||||
|
return buffer
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (session *sessionData) finishUpdateScript(htmlID string) {
|
||||||
|
if buffer, ok := session.updateScripts[htmlID]; ok {
|
||||||
|
buffer.WriteString("scanElementsSize();\n}\n")
|
||||||
|
session.runScript(buffer.String())
|
||||||
|
freeStringBuilder(buffer)
|
||||||
|
delete(session.updateScripts, htmlID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func sizeConstant(session Session, tag string) (SizeUnit, bool) {
|
func sizeConstant(session Session, tag string) (SizeUnit, bool) {
|
||||||
if text, ok := session.Constant(tag); ok {
|
if text, ok := session.Constant(tag); ok {
|
||||||
return StringToSizeUnit(text)
|
return StringToSizeUnit(text)
|
||||||
|
@ -58,19 +83,36 @@ func appendToInnerHTML(htmlID, content string, session Session) {
|
||||||
|
|
||||||
func updateProperty(htmlID, property, value string, session Session) {
|
func updateProperty(htmlID, property, value string, session Session) {
|
||||||
if !session.ignoreViewUpdates() {
|
if !session.ignoreViewUpdates() {
|
||||||
|
if buffer := session.updateScript(htmlID); buffer != nil {
|
||||||
|
buffer.WriteString(fmt.Sprintf(`element.setAttribute('%v', '%v');`, property, value))
|
||||||
|
buffer.WriteRune('\n')
|
||||||
|
} else {
|
||||||
session.runScript(fmt.Sprintf(`updateProperty('%v', '%v', '%v');`, htmlID, property, value))
|
session.runScript(fmt.Sprintf(`updateProperty('%v', '%v', '%v');`, htmlID, property, value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func updateCSSProperty(htmlID, property, value string, session Session) {
|
func updateCSSProperty(htmlID, property, value string, session Session) {
|
||||||
if !session.ignoreViewUpdates() {
|
if !session.ignoreViewUpdates() {
|
||||||
|
if buffer := session.updateScript(htmlID); buffer != nil {
|
||||||
|
buffer.WriteString(fmt.Sprintf(`element.style['%v'] = '%v';`, property, value))
|
||||||
|
buffer.WriteRune('\n')
|
||||||
|
} else {
|
||||||
session.runScript(fmt.Sprintf(`updateCSSProperty('%v', '%v', '%v');`, htmlID, property, value))
|
session.runScript(fmt.Sprintf(`updateCSSProperty('%v', '%v', '%v');`, htmlID, property, value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func updateBoolProperty(htmlID, property string, value bool, session Session) {
|
func updateBoolProperty(htmlID, property string, value bool, session Session) {
|
||||||
if !session.ignoreViewUpdates() {
|
if !session.ignoreViewUpdates() {
|
||||||
|
if buffer := session.updateScript(htmlID); buffer != nil {
|
||||||
if value {
|
if value {
|
||||||
|
buffer.WriteString(fmt.Sprintf(`element.setAttribute('%v', true);`, property))
|
||||||
|
} else {
|
||||||
|
buffer.WriteString(fmt.Sprintf(`element.setAttribute('%v', false);`, property))
|
||||||
|
}
|
||||||
|
buffer.WriteRune('\n')
|
||||||
|
} else if value {
|
||||||
session.runScript(fmt.Sprintf(`updateProperty('%v', '%v', true);`, htmlID, property))
|
session.runScript(fmt.Sprintf(`updateProperty('%v', '%v', true);`, htmlID, property))
|
||||||
} else {
|
} else {
|
||||||
session.runScript(fmt.Sprintf(`updateProperty('%v', '%v', false);`, htmlID, property))
|
session.runScript(fmt.Sprintf(`updateProperty('%v', '%v', false);`, htmlID, property))
|
||||||
|
@ -80,9 +122,14 @@ func updateBoolProperty(htmlID, property string, value bool, session Session) {
|
||||||
|
|
||||||
func removeProperty(htmlID, property string, session Session) {
|
func removeProperty(htmlID, property string, session Session) {
|
||||||
if !session.ignoreViewUpdates() {
|
if !session.ignoreViewUpdates() {
|
||||||
|
if buffer := session.updateScript(htmlID); buffer != nil {
|
||||||
|
buffer.WriteString(fmt.Sprintf(`if (element.hasAttribute('%v')) { element.removeAttribute('%v');}`, property, property))
|
||||||
|
buffer.WriteRune('\n')
|
||||||
|
} else {
|
||||||
session.runScript(fmt.Sprintf(`removeProperty('%v', '%v');`, htmlID, property))
|
session.runScript(fmt.Sprintf(`removeProperty('%v', '%v');`, htmlID, property))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
func setDisabled(htmlID string, disabled bool, session Session) {
|
func setDisabled(htmlID string, disabled bool, session Session) {
|
||||||
|
|
28
view.go
28
view.go
|
@ -402,18 +402,32 @@ func viewPropertyChanged(view *viewData, tag string) {
|
||||||
|
|
||||||
case Border:
|
case Border:
|
||||||
if getBorder(view, Border) == nil {
|
if getBorder(view, Border) == nil {
|
||||||
|
buffer := session.updateScript(htmlID)
|
||||||
|
if buffer == nil {
|
||||||
|
session.startUpdateScript(htmlID)
|
||||||
|
}
|
||||||
updateCSSProperty(htmlID, BorderWidth, "", session)
|
updateCSSProperty(htmlID, BorderWidth, "", session)
|
||||||
updateCSSProperty(htmlID, BorderColor, "", session)
|
updateCSSProperty(htmlID, BorderColor, "", session)
|
||||||
updateCSSProperty(htmlID, BorderStyle, "none", session)
|
updateCSSProperty(htmlID, BorderStyle, "none", session)
|
||||||
|
if buffer == nil {
|
||||||
|
session.finishUpdateScript(htmlID)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|
||||||
case BorderLeft, BorderRight, BorderTop, BorderBottom:
|
case BorderLeft, BorderRight, BorderTop, BorderBottom:
|
||||||
if border := getBorder(view, Border); border != nil {
|
if border := getBorder(view, Border); border != nil {
|
||||||
|
buffer := session.updateScript(htmlID)
|
||||||
|
if buffer == nil {
|
||||||
|
session.startUpdateScript(htmlID)
|
||||||
|
}
|
||||||
updateCSSProperty(htmlID, BorderWidth, border.cssWidthValue(session), session)
|
updateCSSProperty(htmlID, BorderWidth, border.cssWidthValue(session), session)
|
||||||
updateCSSProperty(htmlID, BorderColor, border.cssColorValue(session), session)
|
updateCSSProperty(htmlID, BorderColor, border.cssColorValue(session), session)
|
||||||
updateCSSProperty(htmlID, BorderStyle, border.cssStyleValue(session), session)
|
updateCSSProperty(htmlID, BorderStyle, border.cssStyleValue(session), session)
|
||||||
|
if buffer == nil {
|
||||||
|
session.finishUpdateScript(htmlID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -510,8 +524,15 @@ func viewPropertyChanged(view *viewData, tag string) {
|
||||||
text = filter.cssStyle(session)
|
text = filter.cssStyle(session)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
buffer := session.updateScript(htmlID)
|
||||||
|
if buffer == nil {
|
||||||
|
session.startUpdateScript(htmlID)
|
||||||
|
}
|
||||||
updateCSSProperty(htmlID, "-webkit-backdrop-filter", text, session)
|
updateCSSProperty(htmlID, "-webkit-backdrop-filter", text, session)
|
||||||
updateCSSProperty(htmlID, tag, text, session)
|
updateCSSProperty(htmlID, tag, text, session)
|
||||||
|
if buffer == nil {
|
||||||
|
session.finishUpdateScript(htmlID)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
|
|
||||||
case FontName:
|
case FontName:
|
||||||
|
@ -585,6 +606,10 @@ func viewPropertyChanged(view *viewData, tag string) {
|
||||||
return
|
return
|
||||||
|
|
||||||
case UserSelect:
|
case UserSelect:
|
||||||
|
buffer := session.updateScript(htmlID)
|
||||||
|
if buffer == nil {
|
||||||
|
session.startUpdateScript(htmlID)
|
||||||
|
}
|
||||||
if userSelect, ok := boolProperty(view, UserSelect, session); ok {
|
if userSelect, ok := boolProperty(view, UserSelect, session); ok {
|
||||||
if userSelect {
|
if userSelect {
|
||||||
updateCSSProperty(htmlID, "-webkit-user-select", "auto", session)
|
updateCSSProperty(htmlID, "-webkit-user-select", "auto", session)
|
||||||
|
@ -597,6 +622,9 @@ func viewPropertyChanged(view *viewData, tag string) {
|
||||||
updateCSSProperty(htmlID, "-webkit-user-select", "", session)
|
updateCSSProperty(htmlID, "-webkit-user-select", "", session)
|
||||||
updateCSSProperty(htmlID, "user-select", "", session)
|
updateCSSProperty(htmlID, "user-select", "", session)
|
||||||
}
|
}
|
||||||
|
if buffer == nil {
|
||||||
|
session.finishUpdateScript(htmlID)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
viewUtils.go
12
viewUtils.go
|
@ -47,20 +47,20 @@ func SetChangeListener(view View, viewID, tag string, listener func(View, string
|
||||||
// true - all properties were set successful,
|
// true - all properties were set successful,
|
||||||
// false - error (incompatible type or invalid format of a string value, see AppLog).
|
// false - error (incompatible type or invalid format of a string value, see AppLog).
|
||||||
func SetParams(rootView View, viewID string, params Params) bool {
|
func SetParams(rootView View, viewID string, params Params) bool {
|
||||||
var view View
|
|
||||||
if viewID != "" {
|
if viewID != "" {
|
||||||
view = ViewByID(rootView, viewID)
|
rootView = ViewByID(rootView, viewID)
|
||||||
} else {
|
|
||||||
view = rootView
|
|
||||||
}
|
}
|
||||||
if view == nil {
|
if rootView == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
session := rootView.Session()
|
||||||
|
session.startUpdateScript(rootView.htmlID())
|
||||||
result := true
|
result := true
|
||||||
for tag, value := range params {
|
for tag, value := range params {
|
||||||
result = view.Set(tag, value) && result
|
result = rootView.Set(tag, value) && result
|
||||||
}
|
}
|
||||||
|
session.finishUpdateScript(rootView.htmlID())
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue