diff --git a/widgets/component/props.go b/widgets/component/props.go index 1e633be4..bd68e9fe 100644 --- a/widgets/component/props.go +++ b/widgets/component/props.go @@ -112,7 +112,14 @@ func (cProp CloudPropsDSL) replaceAny(data interface{}, root string, replace fun func (cProp CloudPropsDSL) replaceMap(data map[string]interface{}, root string, replace func(cProp CloudPropsDSL) interface{}) error { xpath := fmt.Sprintf(".%s.$%s", cProp.Xpath, cProp.Name) + + // get keys + keys := []string{} for key := range data { + keys = append(keys, key) + } + + for _, key := range keys { path := fmt.Sprintf("%s.%s", root, key) if !strings.HasPrefix(xpath, path) { continue diff --git a/widgets/form/form.go b/widgets/form/form.go index 5ec4fdfa..963d07cc 100644 --- a/widgets/form/form.go +++ b/widgets/form/form.go @@ -4,6 +4,7 @@ import ( "fmt" "path/filepath" "strings" + "sync" jsoniter "github.com/json-iterator/go" "github.com/yaoapp/gou/application" @@ -51,6 +52,7 @@ import ( // Forms the loaded form widgets var Forms map[string]*DSL = map[string]*DSL{} +var lock sync.Mutex // New create a new DSL func New(id string) *DSL { @@ -94,7 +96,14 @@ func Load(cfg config.Config) error { return err } -// LoadFile load table dsl by file +// LoadFileSync load form dsl by file +func LoadFileSync(root string, file string) error { + lock.Lock() + defer lock.Unlock() + return LoadFile(root, file) +} + +// LoadFile load form dsl by file func LoadFile(root string, file string) error { id := share.ID(root, file) diff --git a/widgets/form/process.go b/widgets/form/process.go index f247b1c3..f41131f7 100644 --- a/widgets/form/process.go +++ b/widgets/form/process.go @@ -191,5 +191,5 @@ func processLoad(process *gouProcess.Process) interface{} { } file = strings.TrimPrefix(file, string(os.PathSeparator)) - return LoadFile("forms", file) + return LoadFileSync("forms", file) } diff --git a/widgets/table/process.go b/widgets/table/process.go index 9e740ddf..b90bc685 100644 --- a/widgets/table/process.go +++ b/widgets/table/process.go @@ -318,5 +318,5 @@ func processLoad(process *gouProcess.Process) interface{} { } file = strings.TrimPrefix(file, string(os.PathSeparator)) - return LoadFile("tables", file) + return LoadFileSync("tables", file) } diff --git a/widgets/table/table.go b/widgets/table/table.go index f95683e7..b2145c46 100644 --- a/widgets/table/table.go +++ b/widgets/table/table.go @@ -4,6 +4,7 @@ import ( "fmt" "path/filepath" "strings" + "sync" jsoniter "github.com/json-iterator/go" "github.com/yaoapp/gou/application" @@ -81,6 +82,7 @@ import ( // Tables the loaded table widgets var Tables map[string]*DSL = map[string]*DSL{} +var lock sync.Mutex // New create a new DSL func New(id string) *DSL { @@ -144,6 +146,13 @@ func LoadID(id string, root string) error { return fmt.Errorf("table %s not found", id) } +// LoadFileSync load table dsl by file +func LoadFileSync(root string, file string) error { + lock.Lock() + defer lock.Unlock() + return LoadFile(root, file) +} + // LoadFile load table dsl by file func LoadFile(root string, file string) error {