Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sagdragon opened this issue Apr 28, 2024 · 4 comments
Closed

Comments

@sagdragon
Copy link

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

@lingol
Copy link
Collaborator

lingol commented Apr 28, 2024

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

So no, not in our plans.

@Hao4Chen
Copy link

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

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

@lingol
Copy link
Collaborator

lingol commented Apr 29, 2024

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
Copy link
Collaborator

lingol commented May 6, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants