本文整理汇总了TypeScript中external/gs_tools/src/graph.Graph.get方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Graph.get方法的具体用法?TypeScript Graph.get怎么用?TypeScript Graph.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类external/gs_tools/src/graph.Graph
的用法示例。
在下文中一共展示了Graph.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it(`should setup correctly`, async () => {
const inputEl = Mocks.object('inputEl');
spyOn(input, 'getInputEl_').and.returnValue(Promise.resolve(inputEl));
const mockDisposable = jasmine.createSpyObj('Disposable', ['dispose']);
const spyListen = spyOn(input, 'listenToValueChanges_').and.returnValue(mockDisposable);
const value = 'value';
spyOn(input, 'getInputElValue_').and.returnValue(value);
await input.onHostCreated_();
assert(await Graph.get($inputValue, Graph.getTimestamp(), input)).to.equal(value);
assert(input['getInputElValue_']).to.haveBeenCalledWith(inputEl);
await inputValueProvider('other', input);
assert(input['listenToValueChanges_']).to.haveBeenCalledWith(inputEl, Matchers.anyFunction());
await spyListen.calls.argsFor(0)[1]();
assert(await Graph.get($inputValue, Graph.getTimestamp(), input)).to.equal(value);
});
示例2: async
+ `registration`, async () => {
const triggeredBy = 'triggeredBy';
spyOn(Persona, 'getValue').and.returnValue(triggeredBy);
const origDisposable = DisposableFunction.of(() => undefined);
Graph.createProvider($triggeredByRegistration, origDisposable);
const mockTargetEl =
jasmine.createSpyObj('TargetEl', ['addEventListener', 'removeEventListener']);
const mockRootNode = jasmine.createSpyObj('RootNode', ['querySelector']);
Object.setPrototypeOf(mockRootNode, Element.prototype);
mockRootNode.querySelector.and.returnValue(mockTargetEl);
const mockElement = jasmine.createSpyObj('Element', ['getRootNode']);
mockElement.getRootNode.and.returnValue(mockRootNode);
Object.setPrototypeOf(mockElement, HTMLElement.prototype);
await Graph.createProvider($.host.el.getId(), mockElement);
spyOn(menu, 'onTriggered_');
await menu.onTriggeredByChanged_();
const disposable = await Graph.get($triggeredByRegistration, Graph.getTimestamp(), menu);
disposable!.dispose();
assert(mockTargetEl.removeEventListener).to
.haveBeenCalledWith('gs-action', Matchers.any(Function));
const handler = mockTargetEl.removeEventListener.calls.argsFor(0)[1];
assert(mockTargetEl.addEventListener).to.haveBeenCalledWith('gs-action', handler);
assert(mockRootNode.querySelector).to.haveBeenCalledWith(triggeredBy);
assert(origDisposable.isDisposed()).to.beTrue();
const event = Mocks.object('event');
handler(event);
assert(Persona.getValue).to.haveBeenCalledWith($.host.triggeredBy, menu);
});
示例3: staticId
.addType(NullType)
.build();
const $lastAction = staticId('lastAction', ActionType);
const lastActionProvider = Graph.createProvider($lastAction, null);
const TimestampType = UnionType.builder<number | null>()
.addType(NumberType)
.addType(NullType)
.build();
const $lastActionTimestamp = staticId('lastActionTimestamp', TimestampType);
const lastActionTimestampProvider = Graph.createProvider($lastActionTimestamp, null);
export const ActionTracker = {
async get(time: GraphTime): Promise<Action | null> {
const [lastAction, lastActionTimestamp] = await Promise.all([
Graph.get($lastAction, time),
Graph.get($lastActionTimestamp, time),
]);
if (lastActionTimestamp === null) {
return null;
}
const now = Date.now();
return (now - lastActionTimestamp) < MAX_ACTION_AGE_ ? lastAction : null;
},
async set(action: Action | null): Promise<void> {
return Promise
.all([
lastActionProvider(action),
lastActionTimestampProvider(Date.now()),