diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-04-29 17:50:34 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-05-07 09:22:47 +0200 |
commit | ae8959af74a8d7b4b6a4f282e13ab87fe35f4ff6 (patch) | |
tree | 77765467be9f058d4b9f3bf8a1a665fbf34b11cf /core/src | |
parent | c60f6716b41dde9d1d7b73077b49ad0ee71761ef (diff) | |
download | nextcloud-server-ae8959af74a8d7b4b6a4f282e13ab87fe35f4ff6.tar.gz nextcloud-server-ae8959af74a8d7b4b6a4f282e13ab87fe35f4ff6.zip |
Move OC.get and OC.set to the bundle
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/OC/get_set.js | 56 | ||||
-rw-r--r-- | core/src/OC/index.js | 3 |
2 files changed, 59 insertions, 0 deletions
diff --git a/core/src/OC/get_set.js b/core/src/OC/get_set.js new file mode 100644 index 00000000000..9fafe121387 --- /dev/null +++ b/core/src/OC/get_set.js @@ -0,0 +1,56 @@ +/* + * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * Get a variable by name + * @param {string} name + * @return {*} + */ +export const get = context => name => { + const namespaces = name.split('.') + const tail = namespaces.pop() + + for (var i = 0; i < namespaces.length; i++) { + context = context[namespaces[i]] + if (!context) { + return false + } + } + return context[tail] +} + +/** + * Set a variable by name + * @param {string} name + * @param {*} value + */ +export const set = context => (name, value) => { + const namespaces = name.split(".") + const tail = namespaces.pop() + + for (let i = 0; i < namespaces.length; i++) { + if (!context[namespaces[i]]) { + context[namespaces[i]] = {} + } + context = context[namespaces[i]] + } + context[tail] = value +} diff --git a/core/src/OC/index.js b/core/src/OC/index.js index ab5552c8e57..548d6f544c8 100644 --- a/core/src/OC/index.js +++ b/core/src/OC/index.js @@ -26,6 +26,7 @@ import Config from './config' import ContactsMenu from './contactsmenu' import Dialogs from './dialogs' import EventSource from './eventsource' +import {get, set} from './get_set' import {isUserAdmin} from './admin' import L10N from './l10n' import { @@ -67,6 +68,8 @@ export default { Util, debug, generateUrl, + get: get(window), + set: set(window), getRootPath, filePath, redirect, |