Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
896086a4
Commit
896086a4
authored
Mar 29, 2022
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Mar 29, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update internal reference naming and comments pertaining to config types
parent
e46c106c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
32 deletions
+29
-32
build-settings.js
src/sidebar/config/build-settings.js
+29
-32
No files found.
src/sidebar/config/build-settings.js
View file @
896086a4
...
...
@@ -13,13 +13,13 @@ import * as postMessageJsonRpc from '../util/postmessage-json-rpc';
*/
/**
*
Returns the global embedder ancesto
r frame.
*
Ascend `levels` from `window_` to find the designated embedde
r frame.
*
* @param {number} levels - Number of ancestors levels to ascend
.
* @param {number} levels - Number of ancestors levels to ascend
* @param {Window=} window_
* @return {Window}
*/
function
get
Ancesto
rFrame
(
levels
,
window_
=
window
)
{
function
get
Embedde
rFrame
(
levels
,
window_
=
window
)
{
let
ancestorWindow
=
window_
;
for
(
let
i
=
0
;
i
<
levels
;
i
++
)
{
if
(
ancestorWindow
===
ancestorWindow
.
top
)
{
...
...
@@ -73,14 +73,14 @@ function fetchServiceGroups(configFromHost, rpcSettings) {
}
/**
* Derive RPC settings from the provided `
AnnotatorConfigFromHost
`, if any are present.
* Derive RPC settings from the provided `
ConfigFromAnnotator
`, if any are present.
*
* @param {ConfigFromAnnotator} configFrom
Host
* @param {ConfigFromAnnotator} configFrom
Annotator
* @param {Window} window_
* @return {import('../../types/config').RPCSettings|null}
*/
function
buildRPCSettings
(
configFrom
Host
,
window_
)
{
const
rpcConfig
=
configFrom
Host
.
requestConfigFromFrame
;
function
buildRPCSettings
(
configFrom
Annotator
,
window_
)
{
const
rpcConfig
=
configFrom
Annotator
.
requestConfigFromFrame
;
if
(
!
rpcConfig
)
{
return
null
;
}
else
if
(
...
...
@@ -92,21 +92,20 @@ function buildRPCSettings(configFromHost, window_) {
);
}
return
{
targetFrame
:
get
Ancesto
rFrame
(
rpcConfig
.
ancestorLevel
,
window_
),
targetFrame
:
get
Embedde
rFrame
(
rpcConfig
.
ancestorLevel
,
window_
),
origin
:
rpcConfig
.
origin
,
};
}
/**
* Retrieve ConfigFromHost to use for settings from the ancestor frame indicated
* in `rpcSettings`
* Retrieve host configuration from embedder frame
*
* @param {ConfigFromAnnotator}
hostConfigFromURL
* @param {ConfigFromAnnotator}
configFromAnnotator
* @param {RPCSettings} rpcSettings
* @return {Promise<ConfigFromEmbedder>}
*/
async
function
getEmbedderConfig
(
hostConfigFromURL
,
rpcSettings
)
{
const
hostConfigFromFrame
=
await
postMessageJsonRpc
.
call
(
async
function
getEmbedderConfig
(
configFromAnnotator
,
rpcSettings
)
{
const
configFromEmbedder
=
await
postMessageJsonRpc
.
call
(
rpcSettings
.
targetFrame
,
rpcSettings
.
origin
,
'requestConfig'
,
...
...
@@ -114,49 +113,47 @@ async function getEmbedderConfig(hostConfigFromURL, rpcSettings) {
3000
);
// In the case where the appropriate `ConfigFromHost` is sourced from another
// frame by RPC, the original `ConfigFromHost` (`hostConfigFromURL`) is
// discarded.
// In cases where host configuration is requested from the embedder frame
// (`ConfigFromEmbedder`), `ConfigFromAnnotator` values are discarded.
//
// The `group` property, however, is currently not
available in the remote
// `ConfigFrom
Host
` and needs to be restored. This property is used by the
// The `group` property, however, is currently not
provided by
// `ConfigFrom
Embedder
` and needs to be restored. This property is used by the
// Notebook.
// TODO: Notebook group should be set by alternate means
return
{
...
hostConfigFromFrame
,
...(
hostConfigFromURL
.
group
?
{
group
:
hostConfigFromURL
.
group
}
:
{}),
...
configFromEmbedder
,
...(
configFromAnnotator
.
group
?
{
group
:
configFromAnnotator
.
group
}
:
{}),
};
}
/**
* Build a `SidebarSettings` object by merging the provided `ConfigFromSidebar`
* with
`ConfigFromHost` from an appropriate source
.
* with
host configuration (`ConfigFromAnnotator` OR `ConfigFromEmbedder`)
.
*
* `ConfigFromHost` may come from either:
* - The URL framgent of the sidebar's iframe src, written by the annotator
* when creating the sidebar's iframe, OR
* - By sending an RPC request for host configuration to a designated ancestor
* frame (This is used in the LMS context)
* @see {ConfigFromAnnotator}
* @see {ConfigFromEmbedder}
* @see {ConfigFromHost}
*
* @param {ConfigFromSidebar} configFromSidebar
* @param {Window} window_ - Test seam
* @return {Promise<SidebarSettings>} - The merged settings
*/
export
async
function
buildSettings
(
configFromSidebar
,
window_
=
window
)
{
const
annotatorConfigFromHost
=
hostPageConfig
(
window
);
const
configFromAnnotator
=
hostPageConfig
(
window
);
const
rpcSettings
=
buildRPCSettings
(
annotatorConfigFromHost
,
window_
);
const
rpcSettings
=
buildRPCSettings
(
configFromAnnotator
,
window_
);
let
configFromHost
;
if
(
rpcSettings
)
{
// The presence of RPCSettings indicates that we should
// source the ConfigFromHost from another frame, and potentially load
// the correct groups asynchronously as well.
const
hostConfigFromFrame
=
await
getEmbedderConfig
(
annotatorConfigFromHost
,
const
configFromEmbedder
=
await
getEmbedderConfig
(
configFromAnnotator
,
rpcSettings
);
configFromHost
=
fetchServiceGroups
(
hostConfigFromFrame
,
rpcSettings
);
configFromHost
=
fetchServiceGroups
(
configFromEmbedder
,
rpcSettings
);
}
else
{
configFromHost
=
annotatorConfigFromHost
;
configFromHost
=
configFromAnnotator
;
}
/** @type {SidebarSettings} */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment