summaryrefslogtreecommitdiffstats
path: root/devtools/client/dom/content/actions/grips.js
blob: 3f25d46d3e304e40f0231bf27317a32d331bfb28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* globals DomProvider */
"use strict";

const constants = require("resource://devtools/client/dom/content/constants.js");

/**
 * Used to fetch grip prototype and properties from the backend.
 */
function requestProperties(grip) {
  return {
    grip,
    type: constants.FETCH_PROPERTIES,
    status: "start",
    error: false,
  };
}

/**
 * Executed when grip properties are received from the backend.
 */
function receiveProperties(grip, response, error) {
  return {
    grip,
    type: constants.FETCH_PROPERTIES,
    status: "done",
    response,
    error,
  };
}

/**
 * Used to get properties from the backend and fire an action
 * when they are received.
 */
function fetchProperties(grip) {
  return async ({ dispatch }) => {
    try {
      // Use 'DomProvider' object exposed from the chrome scope.
      const response = await DomProvider.getPrototypeAndProperties(grip);
      dispatch(receiveProperties(grip, response));
    } catch (e) {
      console.error("Error while fetching properties", e);
    }
    DomProvider.onPropertiesFetched();
  };
}

// Exports from this module
exports.requestProperties = requestProperties;
exports.receiveProperties = receiveProperties;
exports.fetchProperties = fetchProperties;