Merge pull request #15403 from nextcloud/refactor/oc-get-set-bundle

Move OC.get and OC.set to the bundle
This commit is contained in:
Morris Jobke 2019-05-07 12:07:09 +02:00 committed by GitHub
commit 5c9b4db994
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 37 deletions

BIN
core/js/dist/main.js vendored

Binary file not shown.

Binary file not shown.

View file

@ -1113,41 +1113,4 @@ if (window.history.pushState) {
else {
$(window).on('hashchange', _.bind(OC.Util.History._onPopState, OC.Util.History));
}
/**
* Get a variable by name
* @param {string} name
* @return {*}
*/
OC.get=function(name) {
var namespaces = name.split(".");
var tail = namespaces.pop();
var context=window;
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
*/
OC.set=function(name, value) {
var namespaces = name.split(".");
var tail = namespaces.pop();
var context=window;
for(var i = 0; i < namespaces.length; i++) {
if(!context[namespaces[i]]){
context[namespaces[i]]={};
}
context = context[namespaces[i]];
}
context[tail]=value;
};

56
core/src/OC/get_set.js Normal file
View file

@ -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
}

View file

@ -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,