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';
...
@@ -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_
* @param {Window=} window_
* @return {Window}
* @return {Window}
*/
*/
function
get
Ancesto
rFrame
(
levels
,
window_
=
window
)
{
function
get
Embedde
rFrame
(
levels
,
window_
=
window
)
{
let
ancestorWindow
=
window_
;
let
ancestorWindow
=
window_
;
for
(
let
i
=
0
;
i
<
levels
;
i
++
)
{
for
(
let
i
=
0
;
i
<
levels
;
i
++
)
{
if
(
ancestorWindow
===
ancestorWindow
.
top
)
{
if
(
ancestorWindow
===
ancestorWindow
.
top
)
{
...
@@ -73,14 +73,14 @@ function fetchServiceGroups(configFromHost, rpcSettings) {
...
@@ -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_
* @param {Window} window_
* @return {import('../../types/config').RPCSettings|null}
* @return {import('../../types/config').RPCSettings|null}
*/
*/
function
buildRPCSettings
(
configFrom
Host
,
window_
)
{
function
buildRPCSettings
(
configFrom
Annotator
,
window_
)
{
const
rpcConfig
=
configFrom
Host
.
requestConfigFromFrame
;
const
rpcConfig
=
configFrom
Annotator
.
requestConfigFromFrame
;
if
(
!
rpcConfig
)
{
if
(
!
rpcConfig
)
{
return
null
;
return
null
;
}
else
if
(
}
else
if
(
...
@@ -92,21 +92,20 @@ function buildRPCSettings(configFromHost, window_) {
...
@@ -92,21 +92,20 @@ function buildRPCSettings(configFromHost, window_) {
);
);
}
}
return
{
return
{
targetFrame
:
get
Ancesto
rFrame
(
rpcConfig
.
ancestorLevel
,
window_
),
targetFrame
:
get
Embedde
rFrame
(
rpcConfig
.
ancestorLevel
,
window_
),
origin
:
rpcConfig
.
origin
,
origin
:
rpcConfig
.
origin
,
};
};
}
}
/**
/**
* Retrieve ConfigFromHost to use for settings from the ancestor frame indicated
* Retrieve host configuration from embedder frame
* in `rpcSettings`
*
*
* @param {ConfigFromAnnotator}
hostConfigFromURL
* @param {ConfigFromAnnotator}
configFromAnnotator
* @param {RPCSettings} rpcSettings
* @param {RPCSettings} rpcSettings
* @return {Promise<ConfigFromEmbedder>}
* @return {Promise<ConfigFromEmbedder>}
*/
*/
async
function
getEmbedderConfig
(
hostConfigFromURL
,
rpcSettings
)
{
async
function
getEmbedderConfig
(
configFromAnnotator
,
rpcSettings
)
{
const
hostConfigFromFrame
=
await
postMessageJsonRpc
.
call
(
const
configFromEmbedder
=
await
postMessageJsonRpc
.
call
(
rpcSettings
.
targetFrame
,
rpcSettings
.
targetFrame
,
rpcSettings
.
origin
,
rpcSettings
.
origin
,
'requestConfig'
,
'requestConfig'
,
...
@@ -114,49 +113,47 @@ async function getEmbedderConfig(hostConfigFromURL, rpcSettings) {
...
@@ -114,49 +113,47 @@ async function getEmbedderConfig(hostConfigFromURL, rpcSettings) {
3000
3000
);
);
// In the case where the appropriate `ConfigFromHost` is sourced from another
// In cases where host configuration is requested from the embedder frame
// frame by RPC, the original `ConfigFromHost` (`hostConfigFromURL`) is
// (`ConfigFromEmbedder`), `ConfigFromAnnotator` values are discarded.
// discarded.
//
//
// The `group` property, however, is currently not
available in the remote
// The `group` property, however, is currently not
provided by
// `ConfigFrom
Host
` and needs to be restored. This property is used by the
// `ConfigFrom
Embedder
` and needs to be restored. This property is used by the
// Notebook.
// Notebook.
// TODO: Notebook group should be set by alternate means
return
{
return
{
...
hostConfigFromFrame
,
...
configFromEmbedder
,
...(
hostConfigFromURL
.
group
?
{
group
:
hostConfigFromURL
.
group
}
:
{}),
...(
configFromAnnotator
.
group
?
{
group
:
configFromAnnotator
.
group
}
:
{}),
};
};
}
}
/**
/**
* Build a `SidebarSettings` object by merging the provided `ConfigFromSidebar`
* 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:
* @see {ConfigFromAnnotator}
* - The URL framgent of the sidebar's iframe src, written by the annotator
* @see {ConfigFromEmbedder}
* when creating the sidebar's iframe, OR
* @see {ConfigFromHost}
* - By sending an RPC request for host configuration to a designated ancestor
* frame (This is used in the LMS context)
*
*
* @param {ConfigFromSidebar} configFromSidebar
* @param {ConfigFromSidebar} configFromSidebar
* @param {Window} window_ - Test seam
* @param {Window} window_ - Test seam
* @return {Promise<SidebarSettings>} - The merged settings
* @return {Promise<SidebarSettings>} - The merged settings
*/
*/
export
async
function
buildSettings
(
configFromSidebar
,
window_
=
window
)
{
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
;
let
configFromHost
;
if
(
rpcSettings
)
{
if
(
rpcSettings
)
{
// The presence of RPCSettings indicates that we should
// The presence of RPCSettings indicates that we should
// source the ConfigFromHost from another frame, and potentially load
// source the ConfigFromHost from another frame, and potentially load
// the correct groups asynchronously as well.
// the correct groups asynchronously as well.
const
hostConfigFromFrame
=
await
getEmbedderConfig
(
const
configFromEmbedder
=
await
getEmbedderConfig
(
annotatorConfigFromHost
,
configFromAnnotator
,
rpcSettings
rpcSettings
);
);
configFromHost
=
fetchServiceGroups
(
hostConfigFromFrame
,
rpcSettings
);
configFromHost
=
fetchServiceGroups
(
configFromEmbedder
,
rpcSettings
);
}
else
{
}
else
{
configFromHost
=
annotatorConfigFromHost
;
configFromHost
=
configFromAnnotator
;
}
}
/** @type {SidebarSettings} */
/** @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