BVB Source Codes

reactide Show plugin.js Source code

Return Download reactide: download plugin.js Source code - Download reactide Source code - Type:.js
  1. "use strict";
  2.  
  3. exports.__esModule = true;
  4.  
  5. var _getIterator2 = require("babel-runtime/core-js/get-iterator");
  6.  
  7. var _getIterator3 = _interopRequireDefault(_getIterator2);
  8.  
  9. var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
  10.  
  11. var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
  12.  
  13. var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");
  14.  
  15. var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
  16.  
  17. var _inherits2 = require("babel-runtime/helpers/inherits");
  18.  
  19. var _inherits3 = _interopRequireDefault(_inherits2);
  20.  
  21. var _optionManager = require("./file/options/option-manager");
  22.  
  23. var _optionManager2 = _interopRequireDefault(_optionManager);
  24.  
  25. var _babelMessages = require("babel-messages");
  26.  
  27. var messages = _interopRequireWildcard(_babelMessages);
  28.  
  29. var _store = require("../store");
  30.  
  31. var _store2 = _interopRequireDefault(_store);
  32.  
  33. var _babelTraverse = require("babel-traverse");
  34.  
  35. var _babelTraverse2 = _interopRequireDefault(_babelTraverse);
  36.  
  37. var _assign = require("lodash/assign");
  38.  
  39. var _assign2 = _interopRequireDefault(_assign);
  40.  
  41. var _clone = require("lodash/clone");
  42.  
  43. var _clone2 = _interopRequireDefault(_clone);
  44.  
  45. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  46.  
  47. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  48.  
  49. var GLOBAL_VISITOR_PROPS = ["enter", "exit"];
  50.  
  51. var Plugin = function (_Store) {
  52.   (0, _inherits3.default)(Plugin, _Store);
  53.  
  54.   function Plugin(plugin, key) {
  55.     (0, _classCallCheck3.default)(this, Plugin);
  56.  
  57.     var _this = (0, _possibleConstructorReturn3.default)(this, _Store.call(this));
  58.  
  59.     _this.initialized = false;
  60.     _this.raw = (0, _assign2.default)({}, plugin);
  61.     _this.key = _this.take("name") || key;
  62.  
  63.     _this.manipulateOptions = _this.take("manipulateOptions");
  64.     _this.post = _this.take("post");
  65.     _this.pre = _this.take("pre");
  66.     _this.visitor = _this.normaliseVisitor((0, _clone2.default)(_this.take("visitor")) || {});
  67.     return _this;
  68.   }
  69.  
  70.   Plugin.prototype.take = function take(key) {
  71.     var val = this.raw[key];
  72.     delete this.raw[key];
  73.     return val;
  74.   };
  75.  
  76.   Plugin.prototype.chain = function chain(target, key) {
  77.     if (!target[key]) return this[key];
  78.     if (!this[key]) return target[key];
  79.  
  80.     var fns = [target[key], this[key]];
  81.  
  82.     return function () {
  83.       var val = void 0;
  84.  
  85.       for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  86.         args[_key] = arguments[_key];
  87.       }
  88.  
  89.       for (var _iterator = fns, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
  90.         var _ref;
  91.  
  92.         if (_isArray) {
  93.           if (_i >= _iterator.length) break;
  94.           _ref = _iterator[_i++];
  95.         } else {
  96.           _i = _iterator.next();
  97.           if (_i.done) break;
  98.           _ref = _i.value;
  99.         }
  100.  
  101.         var fn = _ref;
  102.  
  103.         if (fn) {
  104.           var ret = fn.apply(this, args);
  105.           if (ret != null) val = ret;
  106.         }
  107.       }
  108.       return val;
  109.     };
  110.   };
  111.  
  112.   Plugin.prototype.maybeInherit = function maybeInherit(loc) {
  113.     var inherits = this.take("inherits");
  114.     if (!inherits) return;
  115.  
  116.     inherits = _optionManager2.default.normalisePlugin(inherits, loc, "inherits");
  117.  
  118.     this.manipulateOptions = this.chain(inherits, "manipulateOptions");
  119.     this.post = this.chain(inherits, "post");
  120.     this.pre = this.chain(inherits, "pre");
  121.     this.visitor = _babelTraverse2.default.visitors.merge([inherits.visitor, this.visitor]);
  122.   };
  123.  
  124.   Plugin.prototype.init = function init(loc, i) {
  125.     if (this.initialized) return;
  126.     this.initialized = true;
  127.  
  128.     this.maybeInherit(loc);
  129.  
  130.     for (var key in this.raw) {
  131.       throw new Error(messages.get("pluginInvalidProperty", loc, i, key));
  132.     }
  133.   };
  134.  
  135.   Plugin.prototype.normaliseVisitor = function normaliseVisitor(visitor) {
  136.     for (var _iterator2 = GLOBAL_VISITOR_PROPS, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
  137.       var _ref2;
  138.  
  139.       if (_isArray2) {
  140.         if (_i2 >= _iterator2.length) break;
  141.         _ref2 = _iterator2[_i2++];
  142.       } else {
  143.         _i2 = _iterator2.next();
  144.         if (_i2.done) break;
  145.         _ref2 = _i2.value;
  146.       }
  147.  
  148.       var key = _ref2;
  149.  
  150.       if (visitor[key]) {
  151.         throw new Error("Plugins aren't allowed to specify catch-all enter/exit handlers. " + "Please target individual nodes.");
  152.       }
  153.     }
  154.  
  155.     _babelTraverse2.default.explode(visitor);
  156.     return visitor;
  157.   };
  158.  
  159.   return Plugin;
  160. }(_store2.default);
  161.  
  162. exports.default = Plugin;
  163. module.exports = exports["default"];
downloadplugin.js Source code - Download reactide Source code
Related Source Codes/Software:
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top