{"size": 778, "ext": "js", "max_stars_repo_path": "packages/hap-dsl-xvm/templates/app/demo/src/global.js", "max_stars_repo_name": "hapjs-platform/hap-toolkit", "max_stars_repo_stars_event_min_datetime": "2022-01-20T07:40:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T06:32:02.000Z", "max_issues_repo_path": "packages/hap-dsl-xvm/templates/app/demo/src/global.js", "max_issues_repo_name": "hapjs-platform/hap-toolkit", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/hap-dsl-xvm/templates/app/demo/src/global.js", "max_forks_repo_name": "hapjs-platform/hap-toolkit", "max_forks_repo_forks_event_min_datetime": "2022-01-20T07:39:36.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-22T02:19:41.000Z"}
{"max_stars_count": 16, "max_issues_count": null, "max_forks_count": 6, "avg_line_length": 19.9487179487, "max_line_length": 103, "alphanum_fraction": 0.7107969152}
/*
 * Copyright (c) 2021, the hapjs-platform Project Contributors
 * SPDX-License-Identifier: Apache-2.0
 */
/**
 * @file 全局能力的配置与获取
 * 文档地址：https://doc.quickapp.cn/tutorial/framework/optimization-skills.html#%E4%BD%BF%E7%94%A8-globaljs
 */

function getGlobalRef() {
  return Object.getPrototypeOf(global) || global
}

const quickappGlobal = getGlobalRef()

/**
 * 设置全局(被APP与Page共享)数据；
 * @param key {string}
 * @param val {*}
 */
function setGlobalData(key, val) {
  quickappGlobal[key] = val
}

/**
 * 获取全局(被APP与Page共享)数据；
 * @param key {string}
 * @return {*}
 */
function getGlobalData(key) {
  return quickappGlobal[key]
}

// 两个方法默认定义在全局
setGlobalData('setGlobalData', setGlobalData)
setGlobalData('getGlobalData', getGlobalData)

export { setGlobalData, getGlobalData }
