grips.js (1439B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 /* globals DomProvider */ 5 "use strict"; 6 7 const constants = require("resource://devtools/client/dom/content/constants.js"); 8 9 /** 10 * Used to fetch grip prototype and properties from the backend. 11 */ 12 function requestProperties(grip) { 13 return { 14 grip, 15 type: constants.FETCH_PROPERTIES, 16 status: "start", 17 error: false, 18 }; 19 } 20 21 /** 22 * Executed when grip properties are received from the backend. 23 */ 24 function receiveProperties(grip, response, error) { 25 return { 26 grip, 27 type: constants.FETCH_PROPERTIES, 28 status: "done", 29 response, 30 error, 31 }; 32 } 33 34 /** 35 * Used to get properties from the backend and fire an action 36 * when they are received. 37 */ 38 function fetchProperties(grip) { 39 return async ({ dispatch }) => { 40 try { 41 // Use 'DomProvider' object exposed from the chrome scope. 42 const response = await DomProvider.getPrototypeAndProperties(grip); 43 dispatch(receiveProperties(grip, response)); 44 } catch (e) { 45 console.error("Error while fetching properties", e); 46 } 47 DomProvider.onPropertiesFetched(); 48 }; 49 } 50 51 // Exports from this module 52 exports.requestProperties = requestProperties; 53 exports.receiveProperties = receiveProperties; 54 exports.fetchProperties = fetchProperties;