UNPKG

ricejs

Version:

Architecture for development of applications with javascript with high capacity of integration to diverse frameworks.

1 lines 11.8 kB
{"filter":false,"title":"rice.js","tooltip":"/src/rice.js","undoManager":{"mark":1,"position":1,"stack":[[{"start":{"row":0,"column":0},"end":{"row":224,"column":0},"action":"remove","lines":["var __RiceData = {","\t\"_\": {","\t\t\"services\": {},","\t\t\"servicesLoaded\": {},","\t\t\"globals\": {},","\t\t\"cache\": {},","\t\t\"constructors\": [],","\t\t\"controllers\": {},","\t\t\"config\": {","\t\t\t\"test\": {","\t\t\t\t\"ok\": true","\t\t\t}","\t\t},","\t\t\"build\": {}","\t}","}","","function RiceCore() {","\tvar rice = {","\t\t\"service\": {},","\t\t\"controller\": {}","\t}","","\trice.name = \"Rice!\"","","\trice._getData = () => {","\t\treturn __RiceData;","\t}","","\trice.addConstructor = (build) => {","\t\t__RiceData._.constructors.push(build);","\t};","","\trice.init = () => {","\t\tfor (let name in __RiceData._.constructors) {","\t\t\tlet constructor = __RiceData._.constructors[name].call(rice);","","\t\t\tif (constructor) {","\t\t\t\trice = constructor;","\t\t\t}","\t\t}","","\t\treturn rice;","\t}","","\trice.addConfig = (name, value) => {","\t\tfunction addConfig(name, value) {","\t\t\tif (mapping(__RiceData._.config, name)) {","\t\t\t\treturn console.error(`There is already an item named \"${name}\" in config. To update this item use setConfig ()`)","\t\t\t}","","\t\t\tmapping(__RiceData._.config, name, value)","\t\t}","","\t\tif (typeof name == \"object\") {","\t\t\tfor (let key in name) {","\t\t\t\taddConfig(key, name[key])","\t\t\t}","\t\t} else {","\t\t\taddConfig(name, value)","\t\t}","\t}","","\trice.setConfig = (name, value) => {","\t\tfunction setConfig(name, value) {","\t\t\tmapping(__RiceData._.config, name, value)","\t\t}","","\t\tif (typeof name == \"object\") {","\t\t\tfor (let key in name) {","\t\t\t\tsetConfig(key, name[key])","\t\t\t}","\t\t} else {","\t\t\tsetConfig(name, value)","\t\t}","\t}","","\trice.getConfig = (item) => {","\t\treturn mapping(__RiceData._.config, item)","\t}","","\trice.add = (name, value) => {","\t\tif (rice[name]) {","\t\t\treturn console.error(`\"Rice.${name}\" was not created. A key with this name already exists.`)","\t\t}","","\t\trice[name] = value;","\t\treturn rice;","\t}","","","","\trice.build = (name, build) => {","\t\tif (!__RiceData._.build[name]) {","\t\t\t__RiceData._.build[name] = {}","\t\t}","","\t\tvar _rice = rice;","","\t\t_rice.addData = (key, value) => {","\t\t\tif (!__RiceData._.build[name][key]) {","\t\t\t\treturn __RiceData._.build[name][key] = value;","\t\t\t} else {","\t\t\t\tconsole.error(`rice-${name}: \"${key}\" was not created. A key with this name already exists.`)","\t\t\t\treturn undefined;","\t\t\t}","\t\t}","","\t\t_rice.setData = (key, value) => {","\t\t\t__RiceData._.build[name][key] = value;","\t\t}","","\t\t_rice.getData = (key) => {","\t\t\treturn __RiceData._.build[name][key];","\t\t}","","\t\tvar done = build.apply(rice)","","\t\tif (done) {","\t\t\treturn Rice = done;","\t\t}","","\t\treturn rice;","\t}","","\trice.cache = (name, value) => {","\t\tif (!value) {","\t\t\treturn __RiceData._.cache[name] ? __RiceData._.cache[name] : undefined;","\t\t} else {","\t\t\t__RiceData._.cache[name] = value;","\t\t}","\t}","","\trice.global = (name, value) => {","\t\tif (value == undefined) {","\t\t\treturn __RiceData._.globals[name] ? __RiceData._.globals[name] : undefined;","\t\t} else {","\t\t\t__RiceData._.globals[name] = value;","\t\t}","\t}","","\trice.addService = (name, value) => {","\t\tif (__RiceData._.services[name]) {","\t\t\treturn console.error(`Can not create the \"${name}\" service. Another service with this name already exists`)","\t\t}","","\t\t__RiceData._.services[name] = value;","\t}","","\trice.initService = (name, ...args) => {","\t\tif (!__RiceData._.services[name]) {","\t\t\treturn console.error(`There is no registered service called \"${name}\"`)","\t\t}","","\t\trice.service[name] = __RiceData._.services[name].apply(null, args);","","\t\tif (rice.service[name].init) {","\t\t\trice.service[name].init();","\t\t}","\t}","","\trice.initAllServices = (args = {}) => {","\t\tfor (let name in __RiceData._.services) {","\t\t\tvar arg = [name]","","\t\t\tif (args[name]) {","\t\t\t\tif (Array.isArray(args[name])) {","\t\t\t\t\targs[name].map((item) => {","\t\t\t\t\t\targ.push(args[item])","\t\t\t\t\t})","\t\t\t\t} else {","\t\t\t\t\targ.push(args[name])","\t\t\t\t}","\t\t\t}","","\t\t\trice.initService.apply(null, arg)","\t\t}","\t}","","\trice.stopService = (name) => {","\t\tif (rice.service[name]) {","\t\t\tif (rice.service[name].stop) {","\t\t\t\trice.service[name].stop(() => {","\t\t\t\t\tdelete rice.service[name];","\t\t\t\t})","\t\t\t} else {","\t\t\t\tdelete rice.service[name]","\t\t\t}","","\t\t\tdelete __RiceData._.services[name]","\t\t}","\t}","","\trice.stopAllServices = function (name) {","\t\tfor (let name in rice.service) {","\t\t\trice.stopService(name)","\t\t}","\t}","","\trice.addController = function (name, controller) {","\t\t__RiceData._.controllers[name] = controller;","\t}","","\trice.controller = function (name, ...args) {","\t\ttry {","\t\t\tvar control = __RiceData._.controllers[name]","\t\t\treturn control.apply(null, args);","\t\t} catch (e) {","\t\t\tif (!__RiceData._.controllers[name]) {","\t\t\t\treturn console.error(`The controller \"${name}\" has not been registered. Use Rice.addController(\"${name}\", function(){...}) to register it.`)","\t\t\t} else {","\t\t\t\tconsole.error(e)","\t\t\t}","\t\t}","\t}","","\treturn rice;","}","","if (typeof module == \"object\" && typeof module.exports == \"object\") {","\tmodule.exports = new RiceCore();","} else {","\tvar Rice = new RiceCore();","}",""],"id":2}],[{"start":{"row":0,"column":0},"end":{"row":239,"column":0},"action":"insert","lines":["var __RiceData = {","\t\"_\": {","\t\t\"services\": {},","\t\t\"servicesLoaded\": {},","\t\t\"globals\": {},","\t\t\"cache\": {},","\t\t\"constructors\": [],","\t\t\"controllers\": {},","\t\t\"config\": {","\t\t\t\"test\": {","\t\t\t\t\"ok\": true","\t\t\t}","\t\t},","\t\t\"build\": {}","\t}","}","","function RiceCore() {","\tvar rice = {","\t\t\"service\": {},","\t\t\"controller\": {}","\t}","","\trice.name = \"Rice!\"","","\trice._getData = () => {","\t\treturn __RiceData;","\t}","","\trice.addConstructor = (build) => {","\t\t__RiceData._.constructors.push(build);","\t};","","\trice.init = () => {","\t\tfor (let name in __RiceData._.constructors) {","\t\t\tlet constructor = __RiceData._.constructors[name].call(rice);","","\t\t\tif (constructor) {","\t\t\t\trice = constructor;","\t\t\t}","\t\t}","","\t\treturn rice;","\t}","","\trice.addConfig = (name, value) => {","\t\tfunction addConfig(name, value) {","\t\t\tif (mapping(__RiceData._.config, name)) {","\t\t\t\treturn console.error(`There is already an item named \"${name}\" in config. To update this item use setConfig ()`)","\t\t\t}","","\t\t\tmapping(__RiceData._.config, name, value)","\t\t}","","\t\tif (typeof name == \"object\") {","\t\t\tfor (let key in name) {","\t\t\t\taddConfig(key, name[key])","\t\t\t}","\t\t} else {","\t\t\taddConfig(name, value)","\t\t}","\t}","","\trice.setConfig = (name, value) => {","\t\tfunction setConfig(name, value) {","\t\t\tmapping(__RiceData._.config, name, value)","\t\t}","","\t\tif (typeof name == \"object\") {","\t\t\tfor (let key in name) {","\t\t\t\tsetConfig(key, name[key])","\t\t\t}","\t\t} else {","\t\t\tsetConfig(name, value)","\t\t}","\t}","","\trice.getConfig = (item) => {","\t\treturn mapping(__RiceData._.config, item)","\t}","","\trice.add = (name, value) => {","\t\tif (rice[name]) {","\t\t\treturn console.error(`\"Rice.${name}\" was not created. A key with this name already exists.`)","\t\t}","","\t\trice[name] = value;","\t\treturn rice;","\t}","","","","\trice.build = (name, build) => {","\t\tif (!__RiceData._.build[name]) {","\t\t\t__RiceData._.build[name] = {}","\t\t}","","\t\tvar _rice = rice;","","\t\t_rice.addData = (key, value) => {","\t\t\tif (!__RiceData._.build[name][key]) {","\t\t\t\treturn __RiceData._.build[name][key] = value;","\t\t\t} else {","\t\t\t\tconsole.error(`rice-${name}: \"${key}\" was not created. A key with this name already exists.`)","\t\t\t\treturn undefined;","\t\t\t}","\t\t}","","\t\t_rice.setData = (key, value) => {","\t\t\t__RiceData._.build[name][key] = value;","\t\t}","","\t\t_rice.getData = (key) => {","\t\t\treturn __RiceData._.build[name][key];","\t\t}","","\t\tvar done = build.apply(rice)","","\t\tif (done) {","\t\t\treturn Rice = done;","\t\t}","","\t\treturn rice;","\t}","","\trice.setCache = (name, value) => {","\t\tvar id = uuid();","\t\t__RiceData._.cache[`${id}_${name}`] = value;","\t\treturn id;","\t}","","\trice.getCache = (id, name) => {","\t\tif (name) {","\t\t\treturn __RiceData._.cache[`${id}_${name}`];","\t\t}","","\t\treturn __RiceData._.cache[id];","\t}","","\trice.removeCache = (id, name) => {","\t\tif (name) {","\t\t\tdelete __RiceData._.cache[`${id}_${name}`];","\t\t\treturn;","\t\t}","","\t\tdelete __RiceData._.cache[id];","\t}","","\trice.global = (name, value) => {","\t\tif (value == undefined) {","\t\t\treturn __RiceData._.globals[name] ? __RiceData._.globals[name] : undefined;","\t\t} else {","\t\t\t__RiceData._.globals[name] = value;","\t\t}","\t}","","\trice.addService = (name, value) => {","\t\tif (__RiceData._.services[name]) {","\t\t\treturn console.error(`Can not create the \"${name}\" service. Another service with this name already exists`)","\t\t}","","\t\t__RiceData._.services[name] = value;","\t}","","\trice.initService = (name, ...args) => {","\t\tif (!__RiceData._.services[name]) {","\t\t\treturn console.error(`There is no registered service called \"${name}\"`)","\t\t}","","\t\trice.service[name] = __RiceData._.services[name].apply(null, args);","","\t\tif (rice.service[name].init) {","\t\t\trice.service[name].init();","\t\t}","\t}","","\trice.initAllServices = (args = {}) => {","\t\tfor (let name in __RiceData._.services) {","\t\t\tvar arg = [name]","","\t\t\tif (args[name]) {","\t\t\t\tif (Array.isArray(args[name])) {","\t\t\t\t\targs[name].map((item) => {","\t\t\t\t\t\targ.push(args[item])","\t\t\t\t\t})","\t\t\t\t} else {","\t\t\t\t\targ.push(args[name])","\t\t\t\t}","\t\t\t}","","\t\t\trice.initService.apply(null, arg)","\t\t}","\t}","","\trice.stopService = (name) => {","\t\tif (rice.service[name]) {","\t\t\tif (rice.service[name].stop) {","\t\t\t\trice.service[name].stop(() => {","\t\t\t\t\tdelete rice.service[name];","\t\t\t\t})","\t\t\t} else {","\t\t\t\tdelete rice.service[name]","\t\t\t}","","\t\t\tdelete __RiceData._.services[name]","\t\t}","\t}","","\trice.stopAllServices = function (name) {","\t\tfor (let name in rice.service) {","\t\t\trice.stopService(name)","\t\t}","\t}","","\trice.addController = function (name, controller) {","\t\t__RiceData._.controllers[name] = controller;","\t}","","\trice.controller = function (name, ...args) {","\t\ttry {","\t\t\tvar control = __RiceData._.controllers[name]","\t\t\treturn control.apply(null, args);","\t\t} catch (e) {","\t\t\tif (!__RiceData._.controllers[name]) {","\t\t\t\treturn console.error(`The controller \"${name}\" has not been registered. Use Rice.addController(\"${name}\", function(){...}) to register it.`)","\t\t\t} else {","\t\t\t\tconsole.error(e)","\t\t\t}","\t\t}","\t}","","\treturn rice;","}","","if (typeof module == \"object\" && typeof module.exports == \"object\") {","\tmodule.exports = new RiceCore();","} else {","\tvar Rice = new RiceCore();","}",""],"id":4}]]},"ace":{"folds":[],"scrolltop":0,"scrollleft":0,"selection":{"start":{"row":14,"column":2},"end":{"row":14,"column":2},"isBackwards":false},"options":{"guessTabSize":true,"useWrapMode":false,"wrapToView":true},"firstLineState":0},"timestamp":1491004966214,"hash":"e61a52948dfbd98cdfbb2a8e192e39848c528e10"}