threads.js (1959B)
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 5 import { createThread } from "../client/firefox/create"; 6 import { getSourcesToRemoveForThread } from "../selectors/index"; 7 import { removeSources } from "./sources/removeSources"; 8 9 export function addTarget(targetFront) { 10 return { type: "INSERT_THREAD", newThread: createThread(targetFront) }; 11 } 12 13 export function removeTarget(targetFront) { 14 return async ({ getState, dispatch }) => { 15 const threadActorID = targetFront.targetForm.threadActor; 16 17 // Just before emitting the REMOVE_THREAD action, 18 // synchronously compute the list of source and source actor objects 19 // which should be removed as that one target get removed. 20 // 21 // The list of source objects isn't trivial to compute as these objects 22 // are shared across targets/threads. 23 const { actors, sources } = getSourcesToRemoveForThread( 24 getState(), 25 threadActorID 26 ); 27 28 // Notify the reducers that a target/thread is being removed. 29 // This will be fired on navigation for all existing targets. 30 // That except the top target, when pausing on unload, where the top target may still hold longer. 31 // Also except for service worker targets, which may be kept alive. 32 dispatch({ 33 type: "REMOVE_THREAD", 34 threadActorID, 35 }); 36 // A distinct action is used to notify about all the sources and source actors objects 37 // to be removed. This action is shared by some other codepath. Like removing the pretty printed source. 38 await dispatch(removeSources(sources, actors)); 39 }; 40 } 41 42 export function toggleJavaScriptEnabled(enabled) { 43 return async ({ dispatch, client }) => { 44 await client.toggleJavaScriptEnabled(enabled); 45 dispatch({ 46 type: "TOGGLE_JAVASCRIPT_ENABLED", 47 value: enabled, 48 }); 49 }; 50 }