Skip to content

Commit

Permalink
fix(ohos): fix ts object serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
sohotz authored and etkmao committed Mar 3, 2025
1 parent 344610c commit ec55a02
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export struct ExampleComponentA {
// 自定义事件举例
let event = new HippyViewEvent("onEvent1")
let params = new Map<string, string>()
params['key1'] = 'value1'
params.set('key1', 'value1')
event.send(this.renderView.ctx, this.renderView.tag, params)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,7 @@ export class NativeRenderSerializer extends PrimitiveValueSerializer {
if (object instanceof Map) {
this.assignId(object)
if (object.size > 0) {
let keys = object.keys()
for (let key of keys) {
if(typeof key == 'string') {
this.writeObject(object as Map<string, HippyAny>)
} else {
this.writeMap(object as Map<HippyAny, HippyAny>)
}
break
}
this.writeMap(object as Map<HippyAny, HippyAny>)
} else {
this.writeObject(object as Map<string, HippyAny>)
}
Expand All @@ -70,22 +62,35 @@ export class NativeRenderSerializer extends PrimitiveValueSerializer {
this.writeValue(key)
this.writeValue(value)
})
Object.keys(map).forEach(key => {
count++
if (key == null) {
this.writeString("null")
} else {
this.writeString(key)
}
let value: HippySerValue = Reflect.get(map, key)
this.writeValue(value)
});
this.writeTag(NativeRenderSerializationTag.END_MAP)
this.writer_.putVarint(2 * count)
}

writeObject(map: Map<string, HippyAny>) {
this.writeTag(NativeRenderSerializationTag.BEGIN_OBJECT)
map.forEach((value: HippyAny, key: string) => {
let count = 0
Object.keys(map).forEach(key => {
count++
if (key == null) {
this.writeString("null")
} else {
this.writeString(key)
}
let value: HippySerValue = Reflect.get(map, key)
this.writeValue(value)
})
});
this.writeTag(NativeRenderSerializationTag.END_OBJECT)
this.writer_.putVarint(map.size)
this.writer_.putVarint(count)
}

writeList(list: Array<HippyAny>) {
Expand Down

0 comments on commit ec55a02

Please sign in to comment.