From e84af2595fe1fcd9285c782dabf96e07429cb7c5 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Fri, 24 Jun 2016 15:38:51 +0300 Subject: [PATCH] (slurp "status.js") Former-commit-id: 82c6688648ed771b687d82b91b4167739609f30d --- src/status_im/components/jail.cljs | 108 +---------------------------- src/status_im/utils/slurp.clj | 5 ++ 2 files changed, 7 insertions(+), 106 deletions(-) create mode 100644 src/status_im/utils/slurp.clj diff --git a/src/status_im/components/jail.cljs b/src/status_im/components/jail.cljs index 7efc67c13b..758d620706 100644 --- a/src/status_im/components/jail.cljs +++ b/src/status_im/components/jail.cljs @@ -1,112 +1,8 @@ (ns status-im.components.jail + (:require-macros [status-im.utils.slurp :refer [slurp]]) (:require [status-im.components.react :as r])) -(def status-js - "var _status_catalog = { - commands: {}, - responses: {} -}; - -function Command() { -} -function Response() { -} - -Command.prototype.addToCatalog = function () { - _status_catalog.commands[this.name] = this; -}; - -Command.prototype.param = function (parameter) { - this.params.push(parameter); - - return this; -}; - -Command.prototype.create = function (com) { - this.name = com.name; - this.description = com.description; - this.handler = com.handler; - this.color = com.color; - this.icon = com.icon; - this.params = com.params || []; - this.preview = com.preview; - this.addToCatalog(); - - return this; -}; - - -Response.prototype = Object.create(Command.prototype); -Response.prototype.addToCatalog = function () { - _status_catalog.responses[this.name] = this; -}; -Response.prototype.onReceiveResponse = function (handler) { - this.onReceive = handler; -}; - -function call(pathStr, paramsStr) { - var params = JSON.parse(paramsStr), - path = JSON.parse(pathStr), - fn, res; - - fn = path.reduce(function (catalog, name) { - if (catalog && catalog[name]) { - return catalog[name]; - } - }, - _status_catalog - ); - - res = fn(params); - - return JSON.stringify(res); -} - -function text(options, s) { - return ['text', options, s]; -} - -function view(options, elements) { - return ['view', options].concat(elements); -} - -function image(options) { - return ['image', options]; -} - -function touchable(options, element) { - return ['touchable', options, element]; -} - -function scrollView(options, elements) { - return ['scroll-view', options].concat(elements); -} - -var status = { - command: function (n, d, h) { - var command = new Command(); - return command.create(n, d, h); - }, - response: function (n, d, h) { - var response = new Response(); - return response.create(n, d, h); - }, - types: { - STRING: 'string', - PHONE_NUMBER: 'phone-number', - PASSWORD: 'password' - }, - events: { - SET_VALUE: 'set-value' - }, - components: { - view: view, - text: text, - image: image, - touchable: touchable, - scrollView: scrollView - } -};") +(def status-js (slurp "resources/status.js")) (def jail (when (exists? (.-NativeModules r/react)) diff --git a/src/status_im/utils/slurp.clj b/src/status_im/utils/slurp.clj new file mode 100644 index 0000000000..194b1384b5 --- /dev/null +++ b/src/status_im/utils/slurp.clj @@ -0,0 +1,5 @@ +(ns status-im.utils.slurp + (:refer-clojure :exclude [slurp])) + +(defmacro slurp [file] + (clojure.core/slurp file))