module.exports = function ClassVisitor(state, opts) {
  var json = state.result
    , components = state.seen

  return {
    enter({ node, scope }) {
      var isKnownComponent = isReactComponentClass(node, scope, opts.inferComponent)

      if (isKnownComponent) {
        var component = node.id ? node.id.name : uuid('AnonymousComponent')
          , classBody = node.body.body
          , comment   = doc.parseCommentBlock(node)
          , propTypes = getClassInitializerPropTypes(classBody, scope)
          , defaultProps = getClassInitializerDefaults(classBody, scope);

        components.push(component)

        json[component] = {
          props: {},
          composes: [],
          methods: methodData(classBody),
          desc: comment || '',
          ...json[component]
        }

        parsePropTypes(propTypes, json[component], scope)
        parseDefaultProps(defaultProps, json[component], state.file, scope)
      }
    }
  }
}
    enter: function enter(_ref) {
      var node = _ref.node;
      var scope = _ref.scope;

      var isKnownComponent = isReactComponentClass(node, scope, opts.inferComponent);

      if (isKnownComponent) {
        var component = node.id ? node.id.name : uuid('AnonymousComponent'),
            classBody = node.body.body,
            comment = doc.parseCommentBlock(node),
            propTypes = getClassInitializerPropTypes(classBody, scope),
            defaultProps = getClassInitializerDefaults(classBody, scope);

        components.push(component);

        json[component] = _extends({
          props: {},
          composes: [],
          methods: (0, _componentBodyVisitor2.default)(classBody),
          desc: comment || ''
        }, json[component]);

        parsePropTypes(propTypes, json[component], scope);
        parseDefaultProps(defaultProps, json[component], state.file, scope);
      }
    }
Example #3
0
// Acts as a facade for a Promise, keeping the internal state
// and managing any child transactions.
function Transaction(client, container, config, outerTx) {

  var txid = this.txid = uniqueId('trx')

  this.client    = client
  this.outerTx   = outerTx
  this.trxClient = undefined;
  this._debug    = client.config && client.config.debug

  debug('%s: Starting %s transaction', txid, outerTx ? 'nested' : 'top level')

  this._promise = Promise.using(this.acquireConnection(client, config, txid), (connection) => {

    var trxClient = this.trxClient = makeTxClient(this, client, connection)
    var init      = client.transacting ? this.savepoint(connection) : this.begin(connection)

    init.then(() => {
      return makeTransactor(this, connection, trxClient)
    })
    .then((transactor) => {
      // If we've returned a "thenable" from the transaction container, assume
      // the rollback and commit are chained to this object's success / failure.
      // Directly thrown errors are treated as automatic rollbacks.
      var result
      try {
        result = container(transactor)
      } catch (err) {
        result = Promise.reject(err)
      }
      if (result && result.then && typeof result.then === 'function') {
        result.then((val) => {
          transactor.commit(val)
        })
        .catch((err) => {
          transactor.rollback(err)
        })
      }
    })
    .catch((e) => this._rejecter(e))

    return new Promise((resolver, rejecter) => {
      this._resolver = resolver
      this._rejecter = rejecter
    })
  })

  this._completed  = false

  // If there's a wrapping transaction, we need to wait for any older sibling
  // transactions to settle (commit or rollback) before we can start, and we
  // need to register ourselves with the parent transaction so any younger
  // siblings can wait for us to complete before they can start.
  this._previousSibling = Promise.resolve(true);
  if (outerTx) {
    if (outerTx._lastChild) this._previousSibling = outerTx._lastChild;
    outerTx._lastChild = this._promise;
  }
}
Example #4
0
Storage.store = function(item) {
  var found = Storage.find(item.type, item.attr.id );

  if (!found) {
    item.__unique = getUniqueID();
    instances.push(item);
  } else {
    item.__unique = found.__unique;
    found.attr = item.attr;
  }
};
function getCreatClassName(spec, visitor, scope, comment) {
  var parent = visitor.parentPath.node,
      displayName = find(spec || [], function (node) {
    return t.isProperty(node) && node.key.name === 'displayName';
  }),
      literal = displayName && resolveToValue(displayName.value, scope),
      doclets = doc.getDoclets(comment);

  if (doclets.alias || doclets.name) return doclets.alias || doclets.name;else if (literal) return literal.value;else if (t.isVariableDeclarator(parent)) return parent.id.name;else if (t.isProperty(parent)) return parent.key.name;

  return uuid('AnonymousComponent');
}
Example #6
0
 constructor(props) {
   super(props);
   this.state = {
     id: props.id || uniqueId('map')
   };
 }
Example #7
0
 .tap(function(connection) {
   connection.__knexUid = uniqueId('__knexUid')
   if (poolConfig.afterCreate) {
     return Promise.promisify(poolConfig.afterCreate)(connection)
   }
 })
Example #8
0
// Acts as a facade for a Promise, keeping the internal state
// and managing any child transactions.
function Transaction(client, container, config, outerTx) {
  var _this = this;

  var txid = this.txid = uniqueId('trx');

  this.client = client;
  this.outerTx = outerTx;
  this.trxClient = undefined;
  this._debug = client.config && client.config.debug;

  debug('%s: Starting %s transaction', txid, outerTx ? 'nested' : 'top level');

  this._promise = Promise.using(this.acquireConnection(client, config, txid), function (connection) {

    var trxClient = _this.trxClient = makeTxClient(_this, client, connection);
    var init = client.transacting ? _this.savepoint(connection) : _this.begin(connection);

    init.then(function () {
      return makeTransactor(_this, connection, trxClient);
    }).then(function (transactor) {

      var result = container(transactor);

      // If we've returned a "thenable" from the transaction container,
      // and it's got the transaction object we're running for this, assume
      // the rollback and commit are chained to this object's success / failure.
      if (result && result.then && typeof result.then === 'function') {
        result.then(function (val) {
          transactor.commit(val);
        })['catch'](function (err) {
          transactor.rollback(err);
        });
      }
    })['catch'](function (e) {
      return _this._rejecter(e);
    });

    return new Promise(function (resolver, rejecter) {
      _this._resolver = resolver;
      _this._rejecter = rejecter;
    });
  });

  this._completed = false;

  // If there is more than one child transaction,
  // we queue them, executing each when the previous completes.
  this._childQueue = [];

  // The queue is a noop unless we have child promises.
  this._queue = this._queue || Promise.resolve(true);

  // If there's a wrapping transaction, we need to see if there are
  // any current children in the pending queue.
  if (outerTx) {

    // If there are other promises pending, we just wait until that one
    // settles (commit or rollback) and then we can continue.
    if (outerTx._childQueue.length > 0) {

      this._queue = this._queue.then(function () {
        return Promise.settle(outerTx._childQueue[outerTx._childQueue.length - 1]);
      });
    }

    // Push the current promise onto the queue of promises.
    outerTx._childQueue.push(this._promise);
  }
}
Example #9
0
        .accept('json')
        .query(
          qs.stringify(
            data,
            { arrayFormat: 'brackets' }
          )
        );
    }

    
    /*
      requestId is used on onSuccess callback to allow models to 
      prevent loops when setting same attributes
      multiple times
     */
    let requestId = uniqueId('request_');
    let isCancelled = false;
    let promise = new Promise( (resolve, reject) => {

    	doRequest.end( (err, response) => {

        if (this.onRequestCompleted) this.onRequestCompleted(response);

        let resolveOptions;

	      if (!response.ok) {
	      	let errors = response.body ? response.body.errors : 'Something bad happened';
      		let statusCode = response.status;

      		if (this.onRequestError) this.onRequestError({ statusCode, errors });
 client.acquireRawConnection().tap(function (connection) {
   connection.__knexUid = uniqueId('__knexUid');
   if (poolConfig.afterCreate) {
     return Promise.promisify(poolConfig.afterCreate)(connection);
   }
 }).nodeify(callback);