Skip to content

Commit

Permalink
♻️ #core/context pass TS type-checking (#37185)
Browse files Browse the repository at this point in the history
* Enable TS typecheck throughout core

* Fix up scheduler.js

* Migrate prop type definition to .d.ts

* Fix up prop.js

* Fix up scan.js [stubbed ContextNode type]

* Use type imports

* Fix up values.js

* Circular dependency on values

* Fix up node and update ContextNode type imports

* Fix up subscriber

* Add index and remove last exclusion

* Lint fixes

* Lint fixes

* Remove ref to deleted file

* Fix same-line annotations missing @ type
  • Loading branch information
rcebulko committed Dec 13, 2021
1 parent 584f5a6 commit a8a2e50
Show file tree
Hide file tree
Showing 11 changed files with 382 additions and 333 deletions.
54 changes: 29 additions & 25 deletions src/core/context/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import {ContextNode} from './node';
import {ContextPropDef} from './prop.type';

/**
* @template T, DEP
* @typedef {import('./types.d').IContextProp<T, DEP>} IContextProp
*/

export {contextProp} from './prop';
export {subscribe, unsubscribe} from './subscriber';
Expand All @@ -11,8 +15,8 @@ export {subscribe, unsubscribe} from './subscriber';
*
* See `Element.assignedSlot` API.
*
* @param {!Node} node The target node.
* @param {!Node} slot The slot to which the target node is assigned.
* @param {Node} node The target node.
* @param {Node} slot The slot to which the target node is assigned.
*/
export function assignSlot(node, slot) {
ContextNode.assignSlot(node, slot);
Expand All @@ -22,8 +26,8 @@ export function assignSlot(node, slot) {
* Unassigns the direct slot previously done by the `assignSlot` call.
* Automatically starts the discovery phase for the affected nodes.
*
* @param {!Node} node The target node.
* @param {!Node} slot The slot from which the target node is assigned.
* @param {Node} node The target node.
* @param {Node} slot The slot from which the target node is assigned.
*/
export function unassignSlot(node, slot) {
ContextNode.unassignSlot(node, slot);
Expand All @@ -33,15 +37,15 @@ export function unassignSlot(node, slot) {
* Sets (or unsets) the direct parent. If the parent is set, the node will no
* longer try to discover itself.
*
* @param {!Node} node
* @param {Node} node
* @param {?Node} parent
*/
export function setParent(node, parent) {
ContextNode.get(node).setParent(parent);
}

/**
* @param {!Node} node
* @param {Node} node
*/
export function discover(node) {
ContextNode.get(node).discover();
Expand All @@ -51,7 +55,7 @@ export function discover(node) {
* Designates (or undesignates) the node as a root node. If the node is
* designated as a root, it will no longer discover itself.
*
* @param {!Node} node
* @param {Node} node
* @param {boolean} isRoot
*/
export function setIsRoot(node, isRoot) {
Expand All @@ -61,7 +65,7 @@ export function setIsRoot(node, isRoot) {
/**
* Reruns discovery on the children of the specified node, if any.
*
* @param {!Node} node
* @param {Node} node
*/
export function rediscoverChildren(node) {
ContextNode.rediscoverChildren(node);
Expand All @@ -81,9 +85,9 @@ export function rediscoverChildren(node) {
* Once the input is set, the recalculation is rescheduled asynchronously.
* All dependent properties are also recalculated.
*
* @param {!Node} node The target node.
* @param {!ContextPropDef<T>} prop
* @param {function(T)} setter
* @param {Node} node The target node.
* @param {IContextProp<T, ?>} prop
* @param {function(T):void} setter
* @param {T} value
* @template T
*/
Expand All @@ -95,44 +99,44 @@ export function setProp(node, prop, setter, value) {
* Unsets the input value for the specified property and setter.
* See `setProp()` for more info.
*
* @param {!Node} node The target node.
* @param {!ContextPropDef<T>} prop
* @param {function(T)} setter
* @param {Node} node The target node.
* @param {IContextProp<T, ?>} prop
* @param {function(T):void} setter
* @template T
*/
export function removeProp(node, prop, setter) {
ContextNode.get(node).values.remove(prop, setter);
}

/**
* @param {!Node} node
* @param {Node} node
* @param {string} name
* @param {function(!Node):boolean} match
* @param {function(Node):boolean} match
* @param {number=} weight
*/
export function addGroup(node, name, match, weight = 0) {
ContextNode.get(node).addGroup(name, match, weight);
}

/**
* @param {!Node} node
* @param {Node} node
* @param {string} groupName
* @param {!ContextPropDef<T>} prop
* @param {function(T)} setter
* @param {IContextProp<T, ?>} prop
* @param {function(T):void} setter
* @param {T} value
* @template T
*/
export function setGroupProp(node, groupName, prop, setter, value) {
ContextNode.get(node).group(groupName).values.set(prop, setter, value);
ContextNode.get(node).group(groupName)?.values.set(prop, setter, value);
}

/**
* @param {!Node} node
* @param {Node} node
* @param {string} groupName
* @param {!ContextPropDef<T>} prop
* @param {function(T)} setter
* @param {IContextProp<T, ?>} prop
* @param {function(T):void} setter
* @template T
*/
export function removeGroupProp(node, groupName, prop, setter) {
ContextNode.get(node).group(groupName).values.remove(prop, setter);
ContextNode.get(node).group(groupName)?.values.remove(prop, setter);
}

0 comments on commit a8a2e50

Please sign in to comment.