зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1614502
- Expose utility functions for rendering Activity Stream. r=Mardak
These will be used by a later patch inside of a ChromeWorker using ReactDOMServer. Differential Revision: https://phabricator.services.mozilla.com/D68093
This commit is contained in:
Родитель
06702cde13
Коммит
7908818e65
|
@ -359,6 +359,7 @@ class AboutNewTabChildService extends BaseAboutNewTabService {
|
|||
`${BASE_URL}vendor/redux.js`,
|
||||
`${BASE_URL}vendor/react-redux.js`,
|
||||
`${BASE_URL}data/content/activity-stream.bundle.js`,
|
||||
`${BASE_URL}data/content/newtab-render.js`,
|
||||
];
|
||||
|
||||
for (let script of scripts) {
|
||||
|
|
|
@ -38,6 +38,7 @@ function templateHTML(options) {
|
|||
`${options.baseUrl}vendor/react-redux.js`,
|
||||
`${options.baseUrl}vendor/react-transition-group.js`,
|
||||
`${options.baseUrl}data/content/activity-stream.bundle.js`,
|
||||
`${options.baseUrl}data/content/newtab-render.js`,
|
||||
];
|
||||
|
||||
// Add spacing and script tags
|
||||
|
|
|
@ -11,38 +11,56 @@ import React from "react";
|
|||
import ReactDOM from "react-dom";
|
||||
import { reducers } from "common/Reducers.jsm";
|
||||
|
||||
const store = initStore(reducers);
|
||||
|
||||
new DetectUserSessionStart(store).sendEventOrAddListener();
|
||||
|
||||
// If this document has already gone into the background by the time we've reached
|
||||
// here, we can deprioritize requesting the initial state until the event loop
|
||||
// frees up. If, however, the visibility changes, we then send the request.
|
||||
let didRequest = false;
|
||||
let requestIdleCallbackId = 0;
|
||||
function doRequest() {
|
||||
if (!didRequest) {
|
||||
if (requestIdleCallbackId) {
|
||||
cancelIdleCallback(requestIdleCallbackId);
|
||||
}
|
||||
didRequest = true;
|
||||
store.dispatch(ac.AlsoToMain({ type: at.NEW_TAB_STATE_REQUEST }));
|
||||
}
|
||||
}
|
||||
|
||||
if (document.hidden) {
|
||||
requestIdleCallbackId = requestIdleCallback(doRequest);
|
||||
addEventListener("visibilitychange", doRequest, { once: true });
|
||||
} else {
|
||||
doRequest();
|
||||
}
|
||||
|
||||
ReactDOM.hydrate(
|
||||
export const NewTab = ({ store, isFirstrun }) => (
|
||||
<Provider store={store}>
|
||||
<Base
|
||||
isFirstrun={global.document.location.href === "about:welcome"}
|
||||
strings={global.gActivityStreamStrings}
|
||||
/>
|
||||
</Provider>,
|
||||
document.getElementById("root")
|
||||
<Base isFirstrun={isFirstrun} />
|
||||
</Provider>
|
||||
);
|
||||
|
||||
export function renderWithoutState() {
|
||||
const store = initStore(reducers);
|
||||
new DetectUserSessionStart(store).sendEventOrAddListener();
|
||||
|
||||
// If this document has already gone into the background by the time we've reached
|
||||
// here, we can deprioritize requesting the initial state until the event loop
|
||||
// frees up. If, however, the visibility changes, we then send the request.
|
||||
let didRequest = false;
|
||||
let requestIdleCallbackId = 0;
|
||||
function doRequest() {
|
||||
if (!didRequest) {
|
||||
if (requestIdleCallbackId) {
|
||||
cancelIdleCallback(requestIdleCallbackId);
|
||||
}
|
||||
didRequest = true;
|
||||
store.dispatch(ac.AlsoToMain({ type: at.NEW_TAB_STATE_REQUEST }));
|
||||
}
|
||||
}
|
||||
|
||||
if (document.hidden) {
|
||||
requestIdleCallbackId = requestIdleCallback(doRequest);
|
||||
addEventListener("visibilitychange", doRequest, { once: true });
|
||||
} else {
|
||||
doRequest();
|
||||
}
|
||||
|
||||
ReactDOM.hydrate(
|
||||
<NewTab
|
||||
store={store}
|
||||
isFirstrun={global.document.location.href === "about:welcome"}
|
||||
/>,
|
||||
document.getElementById("root")
|
||||
);
|
||||
}
|
||||
|
||||
export function renderCache(initialState) {
|
||||
const store = initStore(reducers, initialState);
|
||||
new DetectUserSessionStart(store).sendEventOrAddListener();
|
||||
|
||||
ReactDOM.hydrate(
|
||||
<NewTab
|
||||
store={store}
|
||||
isFirstrun={global.document.location.href === "about:welcome"}
|
||||
/>,
|
||||
document.getElementById("root")
|
||||
);
|
||||
}
|
||||
|
|
|
@ -135,9 +135,10 @@ export const queueEarlyMessageMiddleware = ({ getState }) => {
|
|||
* @param {object} intialState (optional) The initial state of the store, if desired
|
||||
* @return {object} A redux store
|
||||
*/
|
||||
export function initStore(reducers) {
|
||||
export function initStore(reducers, initialState) {
|
||||
const store = createStore(
|
||||
mergeStateReducer(combineReducers(reducers)),
|
||||
initialState,
|
||||
global.RPMAddMessageListener &&
|
||||
applyMiddleware(
|
||||
rehydrationMiddleware,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/*! THIS FILE IS AUTO-GENERATED: webpack.system-addon.config.js */
|
||||
var NewtabRenderUtils =
|
||||
/******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
|
@ -91,7 +92,10 @@
|
|||
|
||||
"use strict";
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var common_Actions_jsm__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
|
||||
/* WEBPACK VAR INJECTION */(function(global) {/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "NewTab", function() { return NewTab; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "renderWithoutState", function() { return renderWithoutState; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "renderCache", function() { return renderCache; });
|
||||
/* harmony import */ var common_Actions_jsm__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
|
||||
/* harmony import */ var content_src_components_Base_Base__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
|
||||
/* harmony import */ var content_src_lib_detect_user_session_start__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(73);
|
||||
/* harmony import */ var content_src_lib_init_store__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(6);
|
||||
|
@ -113,42 +117,58 @@ __webpack_require__.r(__webpack_exports__);
|
|||
|
||||
|
||||
|
||||
const store = Object(content_src_lib_init_store__WEBPACK_IMPORTED_MODULE_3__["initStore"])(common_Reducers_jsm__WEBPACK_IMPORTED_MODULE_7__["reducers"]);
|
||||
new content_src_lib_detect_user_session_start__WEBPACK_IMPORTED_MODULE_2__["DetectUserSessionStart"](store).sendEventOrAddListener(); // If this document has already gone into the background by the time we've reached
|
||||
// here, we can deprioritize requesting the initial state until the event loop
|
||||
// frees up. If, however, the visibility changes, we then send the request.
|
||||
|
||||
let didRequest = false;
|
||||
let requestIdleCallbackId = 0;
|
||||
|
||||
function doRequest() {
|
||||
if (!didRequest) {
|
||||
if (requestIdleCallbackId) {
|
||||
cancelIdleCallback(requestIdleCallbackId);
|
||||
}
|
||||
|
||||
didRequest = true;
|
||||
store.dispatch(common_Actions_jsm__WEBPACK_IMPORTED_MODULE_0__["actionCreators"].AlsoToMain({
|
||||
type: common_Actions_jsm__WEBPACK_IMPORTED_MODULE_0__["actionTypes"].NEW_TAB_STATE_REQUEST
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
if (document.hidden) {
|
||||
requestIdleCallbackId = requestIdleCallback(doRequest);
|
||||
addEventListener("visibilitychange", doRequest, {
|
||||
once: true
|
||||
});
|
||||
} else {
|
||||
doRequest();
|
||||
}
|
||||
|
||||
react_dom__WEBPACK_IMPORTED_MODULE_6___default.a.hydrate(react__WEBPACK_IMPORTED_MODULE_5___default.a.createElement(react_redux__WEBPACK_IMPORTED_MODULE_4__["Provider"], {
|
||||
const NewTab = ({
|
||||
store,
|
||||
isFirstrun
|
||||
}) => react__WEBPACK_IMPORTED_MODULE_5___default.a.createElement(react_redux__WEBPACK_IMPORTED_MODULE_4__["Provider"], {
|
||||
store: store
|
||||
}, react__WEBPACK_IMPORTED_MODULE_5___default.a.createElement(content_src_components_Base_Base__WEBPACK_IMPORTED_MODULE_1__["Base"], {
|
||||
isFirstrun: global.document.location.href === "about:welcome",
|
||||
strings: global.gActivityStreamStrings
|
||||
})), document.getElementById("root"));
|
||||
isFirstrun: isFirstrun
|
||||
}));
|
||||
function renderWithoutState() {
|
||||
const store = Object(content_src_lib_init_store__WEBPACK_IMPORTED_MODULE_3__["initStore"])(common_Reducers_jsm__WEBPACK_IMPORTED_MODULE_7__["reducers"]);
|
||||
new content_src_lib_detect_user_session_start__WEBPACK_IMPORTED_MODULE_2__["DetectUserSessionStart"](store).sendEventOrAddListener(); // If this document has already gone into the background by the time we've reached
|
||||
// here, we can deprioritize requesting the initial state until the event loop
|
||||
// frees up. If, however, the visibility changes, we then send the request.
|
||||
|
||||
let didRequest = false;
|
||||
let requestIdleCallbackId = 0;
|
||||
|
||||
function doRequest() {
|
||||
if (!didRequest) {
|
||||
if (requestIdleCallbackId) {
|
||||
cancelIdleCallback(requestIdleCallbackId);
|
||||
}
|
||||
|
||||
didRequest = true;
|
||||
store.dispatch(common_Actions_jsm__WEBPACK_IMPORTED_MODULE_0__["actionCreators"].AlsoToMain({
|
||||
type: common_Actions_jsm__WEBPACK_IMPORTED_MODULE_0__["actionTypes"].NEW_TAB_STATE_REQUEST
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
if (document.hidden) {
|
||||
requestIdleCallbackId = requestIdleCallback(doRequest);
|
||||
addEventListener("visibilitychange", doRequest, {
|
||||
once: true
|
||||
});
|
||||
} else {
|
||||
doRequest();
|
||||
}
|
||||
|
||||
react_dom__WEBPACK_IMPORTED_MODULE_6___default.a.hydrate(react__WEBPACK_IMPORTED_MODULE_5___default.a.createElement(NewTab, {
|
||||
store: store,
|
||||
isFirstrun: global.document.location.href === "about:welcome"
|
||||
}), document.getElementById("root"));
|
||||
}
|
||||
function renderCache(initialState) {
|
||||
const store = Object(content_src_lib_init_store__WEBPACK_IMPORTED_MODULE_3__["initStore"])(common_Reducers_jsm__WEBPACK_IMPORTED_MODULE_7__["reducers"], initialState);
|
||||
new content_src_lib_detect_user_session_start__WEBPACK_IMPORTED_MODULE_2__["DetectUserSessionStart"](store).sendEventOrAddListener();
|
||||
react_dom__WEBPACK_IMPORTED_MODULE_6___default.a.hydrate(react__WEBPACK_IMPORTED_MODULE_5___default.a.createElement(NewTab, {
|
||||
store: store,
|
||||
isFirstrun: global.document.location.href === "about:welcome"
|
||||
}), document.getElementById("root"));
|
||||
}
|
||||
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(1)))
|
||||
|
||||
/***/ }),
|
||||
|
@ -2792,8 +2812,8 @@ const queueEarlyMessageMiddleware = ({
|
|||
* @return {object} A redux store
|
||||
*/
|
||||
|
||||
function initStore(reducers) {
|
||||
const store = Object(redux__WEBPACK_IMPORTED_MODULE_1__["createStore"])(mergeStateReducer(Object(redux__WEBPACK_IMPORTED_MODULE_1__["combineReducers"])(reducers)), global.RPMAddMessageListener && Object(redux__WEBPACK_IMPORTED_MODULE_1__["applyMiddleware"])(rehydrationMiddleware, queueEarlyMessageMiddleware, messageMiddleware));
|
||||
function initStore(reducers, initialState) {
|
||||
const store = Object(redux__WEBPACK_IMPORTED_MODULE_1__["createStore"])(mergeStateReducer(Object(redux__WEBPACK_IMPORTED_MODULE_1__["combineReducers"])(reducers)), initialState, global.RPMAddMessageListener && Object(redux__WEBPACK_IMPORTED_MODULE_1__["applyMiddleware"])(rehydrationMiddleware, queueEarlyMessageMiddleware, messageMiddleware));
|
||||
|
||||
if (global.RPMAddMessageListener) {
|
||||
global.RPMAddMessageListener(INCOMING_MESSAGE_NAME, msg => {
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
/* 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/. */
|
||||
"use strict";
|
||||
|
||||
// exported by activity-stream.bundle.js
|
||||
window.NewtabRenderUtils.renderWithoutState();
|
|
@ -23,6 +23,7 @@ browser.jar:
|
|||
res/activity-stream/data/content/assets/ (./data/content/assets/*)
|
||||
res/activity-stream/data/content/tippytop/ (./data/content/tippytop/*)
|
||||
res/activity-stream/data/content/activity-stream.bundle.js (./data/content/activity-stream.bundle.js)
|
||||
res/activity-stream/data/content/newtab-render.js (./data/content/newtab-render.js)
|
||||
#ifdef XP_MACOSX
|
||||
res/activity-stream/css/activity-stream.css (./css/activity-stream-mac.css)
|
||||
#elifdef XP_WIN
|
||||
|
|
|
@ -29,5 +29,6 @@
|
|||
<script src="resource://activity-stream/vendor/react-redux.js"></script>
|
||||
<script src="resource://activity-stream/vendor/react-transition-group.js"></script>
|
||||
<script src="resource://activity-stream/data/content/activity-stream.bundle.js"></script>
|
||||
<script src="resource://activity-stream/data/content/newtab-render.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -29,5 +29,6 @@
|
|||
<script src="resource://activity-stream/vendor/react-redux.js"></script>
|
||||
<script src="resource://activity-stream/vendor/react-transition-group.js"></script>
|
||||
<script src="resource://activity-stream/data/content/activity-stream.bundle.js"></script>
|
||||
<script src="resource://activity-stream/data/content/newtab-render.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -15,6 +15,7 @@ module.exports = (env = {}) => ({
|
|||
output: {
|
||||
path: absolute("data/content"),
|
||||
filename: "activity-stream.bundle.js",
|
||||
library: "NewtabRenderUtils",
|
||||
},
|
||||
// TODO: switch to eval-source-map for faster builds. Requires CSP changes
|
||||
devtool: env.development ? "inline-source-map" : false,
|
||||
|
|
Загрузка…
Ссылка в новой задаче