本文整理匯總了TypeScript中aerial-common2.weakMemo函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript weakMemo函數的具體用法?TypeScript weakMemo怎麽用?TypeScript weakMemo使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了weakMemo函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: emit
req.on("end", () => emit(JSON.parse(buffer.join(""))));
return () => { };
});
return yield take(chan);
}
function* watchUris(req: express.Request, res: express.Response) {
const data = yield call(getPostData, req);
yield put(watchUrisRequested(data));
res.send([]);
}
const getTranspileOptions = weakMemo((state: ApplicationState) => ({
assignTo: "bundle",
readFileSync: getReadFile(state)
}));
function* getComponentHTMLPreview(req: express.Request, res: express.Response) {
// TODO - evaluate PC code IN THE BROWSER -- need to attach data information to element
// nodes
const state: ApplicationState = yield select();
const { componentId, previewName } = req.params;
const components = (yield call(getAvailableComponents, state, getReadFile(state))) as RegisteredComponent[];
const targetComponent = components.find(component => component.tagName === componentId);
if (!targetComponent || !targetComponent.filePath) {
示例2: weakMemo
export const getSEnvNodeClass = weakMemo((context: any) => {
const SEnvEventTarget = getSEnvEventTargetClass(context);
const SEnvNamedNodeMap = getSEnvNamedNodeMapClass(context);
const { SEnvNodeList } = getSEnvHTMLCollectionClasses(context);
const { SEnvDOMException } = getDOMExceptionClasses(context);
const { SEnvMutationEvent } = getSEnvEventClasses(context);
return class SEnvNode extends SEnvEventTarget implements SEnvNodeInterface {
cloned: boolean;
public $$canBubbleParent: boolean;
public $$parentNode: SEnvParentNodeInterface;
public $$parentElement: HTMLElement;
public $type: string;
public contentLoaded: Promise<any>;
public interactiveLoaded: Promise<any>;
public source: ExpressionLocation;
private _struct: SyntheticNode;
private _constructed: boolean;
readonly structType: string;
readonly attributes: NamedNodeMap;
readonly baseURI: string | null;
childNodes: SEnvNodeListInterface;
readonly localName: string | null;
readonly namespaceURI: string | null;
nodeName: string;
readonly nodeType: number;
nodeValue: string | null;
private _ownerDocument: SEnvDocumentInterface;
textContent: string | null;
private _initialized: boolean;
private _$id: string;
readonly ATTRIBUTE_NODE: number;
readonly CDATA_SECTION_NODE: number;
readonly COMMENT_NODE: number;
readonly DOCUMENT_FRAGMENT_NODE: number;
readonly DOCUMENT_NODE: number;
readonly DOCUMENT_POSITION_CONTAINED_BY: number;
readonly DOCUMENT_POSITION_CONTAINS: number;
readonly DOCUMENT_POSITION_DISCONNECTED: number;
readonly DOCUMENT_POSITION_FOLLOWING: number;
readonly DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: number;
readonly DOCUMENT_POSITION_PRECEDING: number;
readonly DOCUMENT_TYPE_NODE: number;
readonly ELEMENT_NODE: number;
readonly ENTITY_NODE: number;
readonly ENTITY_REFERENCE_NODE: number;
readonly NOTATION_NODE: number;
readonly PROCESSING_INSTRUCTION_NODE: number;
readonly TEXT_NODE: number;
private _assignedSlot: HTMLSlotElement | null;
get assignedSlot() {
return this._assignedSlot;
}
$$setAssignedSlot(value: HTMLSlotElement) {
this._assignedSlot = value;
if (value) {
this.slottedCallback();
} else {
this.unslottedCallback();
}
}
get $id() {
return this._$id;
}
set $id(value: string) {
this._$id = value;
// TODO - probably want to dispatch a mutation change
this._struct = undefined;
}
childNodesArray: Node[];
connectedToDocument: boolean;
constructor() {
super();
this.$id = generateDefaultId();
this.childNodes = this.childNodesArray = new SEnvNodeList();
// called specifically for elements
if (this._constructed) {
throw new Error(`Cannot call constructor twice.`);
}
this._constructed = true;
this.addEventListener(SEnvMutationEvent.MUTATION, this._onMutation.bind(this));
}
initialize() {
}
get ownerDocument() {
//.........這裏部分代碼省略.........
示例3: weakMemo
export const getSEnvNamedNodeMapClass = weakMemo((context: any) => {
const SEnvEventTarget = getSEnvEventTargetClass(context);
return class SEnvNamedNodeMap implements NamedNodeMap {
readonly length: number;
[index:number]: Attr;
getNamedItem(name: string): Attr {
return null;
}
getNamedItemNS(namespaceURI: string | null, localName: string | null): Attr {
return null;
}
item(index: number): Attr {
return null;
}
removeNamedItem(name: string): Attr {
return null;
}
removeNamedItemNS(namespaceURI: string | null, localName: string | null): Attr {
return null;
}
setNamedItem(arg: Attr): Attr {
return null;
}
setNamedItemNS(arg: Attr): Attr {
return null;
}
}
});
示例4: weakMemo
export const getL3EventClasses = weakMemo((context: any) => {
const { SEnvEvent } = getSEnvEventClasses(context);
class SEnvMutationEvent extends SEnvEvent implements MutationEvent {
// public is fine here since MutationEvent interface is used -- these
// props are typically readonly
public attrChange: number;
public attrName: string;
public newValue: string;
public prevValue: string;
public relatedNode: Node;
readonly ADDITION: number;
readonly MODIFICATION: number;
readonly REMOVAL: number;
initMutationEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, relatedNodeArg: Node, prevValueArg: string, newValueArg: string, attrNameArg: string, attrChangeArg: number): void {
super.initEvent(typeArg, canBubbleArg, cancelableArg);
this.relatedNode = relatedNodeArg;
this.prevValue = prevValueArg;
this.newValue = newValueArg;
this.attrName = attrNameArg;
this.attrChange = attrChangeArg;
}
}
return {
SEnvMutationEvent
}
});
示例5: weakMemo
import { weakMemo } from "aerial-common2";
export const getSEnvCollection = weakMemo((context: any) => {
interface Collection<T> extends Array<T> { }
interface CollectionClass {
new<T>(...items: T[]): Collection<T>;
}
const _Collection = function(..._this) {
_this["__proto__"] = this.constructor.prototype;
return _this;
} as any as CollectionClass;
_Collection.prototype = [];
return _Collection;
});
示例6: weakMemo
export const getSEnvEventTargetClass = weakMemo((context?: any) => {
class SEnvEventTarget implements EventTarget {
private ___eventListeners: {
[identifier: string]: EventListenerOrEventListenerObject | EventListenerOrEventListenerObject[]
}
constructor() {
this.___eventListeners = {};
}
addEventListener(type: string, listener?: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) {
if (!this.___eventListeners[type]) {
this.___eventListeners[type] = listener;
} else if (!Array.isArray(this.___eventListeners[type])) {
this.___eventListeners[type] = [this.___eventListeners[type] as EventListenerOrEventListenerObject, listener];
} else {
(this.___eventListeners[type] as EventListenerOrEventListenerObject[]).push(listener);
}
}
dispatchEvent(event: Event): boolean {
const eva = event as EventTargetInterface;
eva.$currentTarget = this;
if (!eva.$target) {
eva.$target = this;
}
const listeners = this.___eventListeners[event.type];
if (!listeners) return false;
if (Array.isArray(listeners)) {
for (const listener of listeners) {
// -- TODO -- check for stopImmediatePropagation
callEventListener(listener, event);
}
} else {
callEventListener(listeners, event);
}
return true;
}
removeEventListener(type: string, listener?: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions) {
const listeners = this.___eventListeners[type];
if (!listeners) return;
if (listeners === listener) {
this.___eventListeners[type] = undefined;
} else if (Array.isArray(listeners)) {
const index = listeners.indexOf(listener);
(listeners as EventListenerOrEventListenerObject[]).splice(index, 1);
if (listeners.length === 1) {
this.___eventListeners[type] = listeners[0];
}
}
}
}
SEnvEventTarget.prototype["___eventListeners"] = {};
return SEnvEventTarget;
});
示例7: weakMemo
export const getSEnvCSSBaseObjectClass = weakMemo((context: any) => {
abstract class SEnvCSSBaseObject implements SEnvCSSObjectInterface {
protected _struct: Struct;
private _$id: string;
get $id() {
return this._$id;
}
set $id(value: string) {
this._$id = value;
this._struct = undefined;
}
abstract previewCSSText: string;
public source: ExpressionLocation;
constructor() {
this._$id = generateDefaultId();
}
get struct(): Struct {
return this._struct || this.resetStruct();
}
abstract $createStruct(): Struct;
protected resetStruct() {
return this._struct = this.$createStruct();
}
clone() {
const clone: SEnvCSSObjectInterface = this.cloneDeep();
clone.source = this.source;
clone["$id"] = this.$id;
return clone;
}
abstract cloneDeep();
}
return SEnvCSSBaseObject;
});
示例8: weakMemo
export const getSEnvParentNodeClass = weakMemo((context: any) => {
const SEnvNode = getSEnvNodeClass(context);
const { SEnvDOMException } = getDOMExceptionClasses(context);
const { SEnvHTMLCollection } = getSEnvHTMLCollectionClasses(context);
const { SEnvMutationEvent } = getL3EventClasses(context);
const { SEnvMutationEvent: SEnvMutationEvent2 } = getSEnvEventClasses(context);
return class SEnvParentNode extends SEnvNode implements ParentNode {
private _children: SEnvHTMLAllCollectionInterface;
constructor() {
super();
this._children = new SEnvHTMLCollection().$init(this);
}
get children() {
return this._children.update();
}
appendChild<T extends Node>(child: T) {
return this.insertChildAt(child, this.childNodes.length);
}
insertBefore<T extends Node>(newChild: T, refChild: Node | null): T {
// if null, then append -- this is to spec. See MSDN docs about this.
if (refChild == null) {
return this.appendChild(newChild);
}
const index = Array.prototype.indexOf.call(this.childNodes, refChild);
if (index === -1) {
throw new SEnvDOMException(`Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.`);
}
if (Array.prototype.indexOf.call(this.childNodes, newChild) !== -1) {
throw new Error(`Inserting child that already exists`);
}
return this.insertChildAt(newChild, index);
}
createStruct(parentNode?: SEnvNodeInterface): SyntheticParentNode {
return {
...(super.createStruct() as any),
childNodes: Array.prototype.map.call(this.childNodes, child => child.struct)
};
}
insertChildAt<T extends Node>(child: T, index: number) {
if (child.nodeType === SEnvNodeTypes.DOCUMENT_FRAGMENT) {
while(child.childNodes.length) {
this.insertChildAt(child.lastChild, index);
}
return child;
}
const c = child as any as SEnvNodeInterface;
if (c.$$parentNode) {
c.$$parentNode.removeChild(child);
}
this.childNodesArray.splice(index, 0, child as any);
const event2 = new SEnvMutationEvent2();
// need to link child _now_ in case connectedCallback triggers additional
// children to be created (web components). We do _not_ want those mutations
// to dispatch a mutation that causes a patch to the DOM renderer
this._linkChild(c);
// dispatch insertion now after it's completely linked
event2.initMutationEvent(createParentNodeInsertChildMutation(this, child, index));
this.dispatchEvent(event2);
return child;
}
removeChild<T extends Node>(child: T) {
const index = this.childNodesArray.indexOf(child);
if (index === -1) {
throw new SEnvDOMException("The node to be removed is not a child of this node.");
}
// needs to come after so that
this.childNodesArray.splice(index, 1);
const event2 = new SEnvMutationEvent2();
event2.initMutationEvent(createParentNodeRemoveChildMutation(this, child, index));
this.dispatchEvent(event2);
this._unlinkChild(child as any as SEnvNodeInterface);
return child;
}
querySelector(selectors: string): Element | null {
return querySelector(this, selectors);
}
getElementsByName(elementName: string): NodeListOf<HTMLElement> {
this._throwUnsupportedMethod();
//.........這裏部分代碼省略.........
示例9: getIdQuery
export const addSyntheticWindow = <TState extends SyntheticBrowserRootState>(root: TState, syntheticBrowserId: string, syntheticWindow: SyntheticWindow): TState => {
const store = root.browserStore;
const idQuery = getIdQuery(syntheticBrowserId);
const { windows } = dsFind(store, idQuery);
return {
...(root as any),
browserStore: dsUpdateOne(store, idQuery, {
windows: [...windows, syntheticWindow]
})
};
}
export const getSyntheticBrowserItemBounds = weakMemo((root: SyntheticBrowserRootState|SyntheticBrowser, item: Partial<Struct & Bounded>) => {
if (!item) return null;
if (item.bounds) return item.bounds;
const window = getSyntheticNodeWindow(root, item.$id);
return window && window.allComputedBounds[item.$id] && shiftBounds(window.allComputedBounds[item.$id], window.bounds);
});
export const getSyntheticBrowserStoreItemByReference = weakMemo((root: SyntheticBrowserRootState|SyntheticBrowser, [type, id]: StructReference) => {
if (type === SYNTHETIC_TEXT_NODE || type === SYNTHETIC_ELEMENT) {
return getSyntheticNodeById(root as any, id);
} else if (type === SYNTHETIC_WINDOW) {
return getSyntheticWindow(root as any, id);
}
});
export const createSyntheticCSSStyleSheet = createStructFactory<SyntheticCSSStyleSheet>(SYNTHETIC_CSS_STYLE_SHEET);
export const createSyntheticCSSStyleRule = createStructFactory<SyntheticCSSStyleRule>(SYNTHETIC_CSS_STYLE_RULE, {
type: CSSRuleType.STYLE_RULE
示例10: if
// for now -- later we can do context.type === "screen"
buffer.push("true");
} else if (MEDIA_PROP_CONVERSION[token]) {
const chunk = getMediaJSExpression(++cursor, tokens, ")");
cursor += chunk.length;
buffer.push(...MEDIA_PROP_CONVERSION[token], `calcMeasurement("${chunk.join(" ")}"`,", context)");
} else if (token === "and") {
buffer.push("&&");
} else if (token === "or" || token === ",") {
buffer.push("&&");
} else {
buffer.push(token);
}
}
return buffer;
}
const translateMediaText = (mediaText: string) => {
return getMediaJSExpression(0, getMediaTextTokens(mediaText)).join(" ");
};
const compileMediaText = weakMemo((mediaText: string) => new Function("context", "calcMeasurement", "getWidth", "getHeight", `return ${translateMediaText(mediaText)}`));
const getWidth = ({ bounds }) => bounds.right - bounds.length;
const getHeight = ({ bounds }) => bounds.bottom - bounds.top;
export const createMediaMatcher = (window: SEnvWindowInterface) => (mediaText: string) => {
return compileMediaText(mediaText)(window, getWidth, getHeight, calcMeasurement);
}