Tencent / MMKV

An efficient, small mobile key-value storage framework developed by WeChat. Works on Android, iOS, macOS, Windows, and POSIX.
Other
17.2k stars 1.89k forks source link

MMKV for HarmonyOS NEXT 是否可以提供自定义对象的存取接口? #1282

Closed sagdragon closed 3 months ago

sagdragon commented 3 months ago

目前最新版本1.3.5支持boolean, number, bigint, string,boolean[], number[], string[], ArrayBuffer类型,是否可以提供自定义对象的存取接口?如果可以提供的话,麻烦回复一下时间、版本计划,多谢。

lingol commented 3 months ago

As far as I learned, there's nothing like Parcel in Android.

So no, not in our plans.

GkLwPp commented 3 months ago

目前最新版本1.3.5支持boolean, number, bigint, string,boolean[], number[], string[], ArrayBuffer类型,是否可以提供自定义对象的存取接口?如果可以提供的话,麻烦回复一下时间、版本计划,多谢。

1.3.5版本对外导出的 是ets文件, 在鸿蒙工程中无法在ts文件 import ets,导致无法使用。 官方是否有计划 将导出ets文件改为ts, 避免有使用限制。

lingol commented 3 months ago

1.3.5版本对外导出的 是ets文件, 在鸿蒙工程中无法在ts文件 import ets,导致无法使用。 官方是否有计划 将导出ets文件改为ts, 避免有使用限制。

How can one do that? I'd love to know. MMKV's wrapper is developed in ArtTS and we don't want to change it to TS. How can we export it as TS without changing the MMKV wrapper from .ets to .ts?

lingol commented 3 months ago

For the time being, you can encode/decode the object into JSON first. It's not ideal but it can get you going.

let user = {
  username: 'lingol',
  age: 21
}

// Serialize the object into a JSON string
mmkv.encodeString('user', JSON.stringify(user))

// Deserialize the JSON string into an object
let jsonUser = mmkv.decodeString('user') // { 'username': 'lingol', 'age': 21 }
let userObject = JSON.parse(jsonUser)