How to use the api/emitter.emit function in api

To help you get started, we’ve selected a few api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 500tech / mimic / lib / api / index.js View on Github external
.then(() => {
            try {
              const dataTree = JSON.parse(data);

              if (!dataTree.version && !dataTree.mocks && !dataTree.groups) {
                resolve({ success: false, error: 'Unsupported format' });
                return;
              }

              const migratedDataTree = migrateData(dataTree);

              Mocks.mergeMocks(migratedDataTree.mocks || [], options);
              Groups.mergeGroups(migratedDataTree.groups || []);
              Emitter.emit(EVENTS.IMPORT);
            } catch (error) {
              if (__ENV === 'development') {
                console.log('Import error', error);
              }

              resolve({ success: false, error: error.message });
            }

            resolve({ success: true });
          });
      }
github 500tech / mimic / lib / api / index.js View on Github external
removeGroup(groupId) {
    Groups.removeGroup(groupId);
    Emitter.emit(EVENTS.UPDATE_GROUP);
  }
github 500tech / mimic / lib / api / utils / worker.js View on Github external
if (mockId) {
        request.mock = API.mocks.filter((mock) => mock.id === mockId)[0];
      }

      if (API.mode === 'remote') {
        Emitter.emit(EVENTS.MIMIC_WEB_WORKER_CAPTURE, { request, response });
      }

      Requests.capture(request, response);
      Emitter.emit(EVENTS.REQUEST_CAPTURED, { requestId: request.id });
    }


    if (messageType === WORKER_MESSAGE_TYPES.MIMIC_EMIT_EVENT) {
      event.stopImmediatePropagation();
      Emitter.emit(event.data.payload.eventType, event.data.payload.args);
    }
  });
github 500tech / mimic / lib / api / index.js View on Github external
addMock() {
    const newMock = Mocks.addMock();
    Emitter.emit(EVENTS.ADD_MOCK);

    return newMock;
  }
github 500tech / mimic / lib / api / index.js View on Github external
updateMock(mockId, request) {
    Mocks.updateMock(mockId, request);
    Emitter.emit(EVENTS.UPDATE_MOCK);
  }
github 500tech / mimic / lib / api / utils / remote.js View on Github external
function onSetData(message) {
  Mocks.setMocks(message.payload);
  Emitter.emit(EVENTS.UPDATE_MOCK);
}
github 500tech / mimic / lib / api / storage.js View on Github external
.then((data) => {
        Object.assign(dataTree, data);
        Emitter.emit(EVENTS.STORAGE_PERSIST);
        Emitter.emit(EVENTS.STORAGE_READY);
      });
  }
github 500tech / mimic / lib / api / utils / remote.js View on Github external
function setResponse(message) {
  const { request, response } = message.payload;

  Requests.setResponse(request.id, response, request.startTime);
  Emitter.emit(EVENTS.RESPONSE_RECEIVED, { requestId: request.id });
}
github 500tech / mimic / lib / api / index.js View on Github external
updateGroup(groupId, group) {
    Groups.updateGroup(groupId, group);
    Emitter.emit(EVENTS.UPDATE_GROUP);
  }
github 500tech / mimic / lib / api / requests.js View on Github external
static capturePending(request) {
    const capturedRequest = new Request({
      id: request.id,
      method: request.method,
      url: request.url,
      params: request.body || request.params,
      headers: request.headers,
      origin: request.origin,
      response: null,
      startTime: request.startTime
    });

    capturedRequests.push(capturedRequest);

    Emitter.emit(EVENTS.REQUEST_CAPTURED, { requestId: request.id });
  }