本文整理汇总了TypeScript中mobx.action函数的典型用法代码示例。如果您正苦于以下问题:TypeScript action函数的具体用法?TypeScript action怎么用?TypeScript action使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了action函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should auto save on change, with a delay', function () {
const product = new Product();
action('change product', () => product.name = 'change 1')();
action('change product again', () => product.name = 'change 2')();
clock.tick(Product.autoSaveDelay);
expect(saveSpy).to.have.been.calledOnce;
expect(saveSpy.args[0][0].name).to.equal('change 2');
});
示例2: getPrivateActionId
export default function mutator<T extends ActionMessage>(
actionCreator: ActionCreator<T>,
target: MutatorFunction<T>
): MutatorFunction<T> {
let actionId = getPrivateActionId(actionCreator);
if (!actionId) {
throw new Error('Mutators can only subscribe to action creators.');
}
// Wrap the callback in a MobX action so it can modify the store
let wrappedTarget = action((actionMessage: T) => {
try {
getGlobalContext().inMutator = true;
if (target(actionMessage) as any) {
throw new Error('Mutators cannot return a value and cannot be async.');
}
} finally {
getGlobalContext().inMutator = false;
}
});
// Subscribe to the action
subscribe(actionId, wrappedTarget);
return target;
}
示例3:
return cacheQueries.map(query=>{
const molecularProfileId = query.molecularProfileId;
const gene = query.hugoGeneSymbol;
const data = oncoprint.props.store.geneMolecularDataCache.result!.get(query)!.data!;
return {
key: `HEATMAPTRACK_${molecularProfileId},${gene}`,
label: gene,
molecularProfileId: molecularProfileId,
molecularAlterationType: molecularProfileIdToMolecularProfile[molecularProfileId].molecularAlterationType,
datatype: molecularProfileIdToMolecularProfile[molecularProfileId].datatype,
data: makeHeatmapTrackData<IGeneHeatmapTrackDatum, 'hugo_gene_symbol'>(
'hugo_gene_symbol',
gene,
sampleMode ? samples : patients,
data
),
trackGroupIndex: molecularProfileIdToHeatmapTracks.get(molecularProfileId)!.trackGroupIndex,
onRemove:action(()=>{
const trackGroup = molecularProfileIdToHeatmapTracks.get(molecularProfileId);
if (trackGroup) {
trackGroup.genes.delete(gene);
if (!trackGroup.genes.size) {
molecularProfileIdToHeatmapTracks.delete(molecularProfileId);
}
}
if (!molecularProfileIdToHeatmapTracks.has(molecularProfileId)
&& oncoprint.sortMode.type === "heatmap"
&& oncoprint.sortMode.clusteredHeatmapProfile === molecularProfileId
) {
oncoprint.sortByData();
}
})
};
});
示例4: makeGenesetHeatmapUnexpandHandler
function makeGenesetHeatmapUnexpandHandler(
oncoprint: ResultsViewOncoprint,
parentKey: string,
expansionEntrezGeneId: number,
myTrackGroup: number,
onRemoveLast: () => void
) {
return action('genesetHeatmapUnexpansion', () => {
const list = oncoprint.expansionsByGenesetHeatmapTrackKey.get(parentKey);
if (list) {
// only remove if the expansion if it isn't needed in another track
// group than the one this track is being removed from; keep the
// expansion if the track is being re-rendered into a different
// track group
if (myTrackGroup === oncoprint.genesetHeatmapTrackGroup) {
// this is a MobX Observable Array, so it should have findIndex
// implemented even in IE
const indexToRemove = list.findIndex(
({entrezGeneId}) => entrezGeneId === expansionEntrezGeneId
);
if (indexToRemove !== -1) {
list.splice(indexToRemove, 1);
if (!list.length) {
onRemoveLast();
}
}
}
} else {
throw new Error(`Track '${parentKey}' has no expansions to remove.`);
}
});
}
示例5: dismiss
@action('dismiss message')
dismiss() {
if (this.dismissCancel) {
this.dismissCancel();
}
this.store.remove(this);
}
示例6: function
browserWindow.on("closed", function() {
action(() =>
windows.splice(windows.findIndex(win => win.browserWindow === browserWindow), 1)
)();
// if no visible window left, app can quit
if (!windows.find(window => window.browserWindow.isVisible())) {
app.quit();
}
});
示例7: constructor
public constructor(v: Date, e: string) {
super('DateValue');
this.errText = e;
this.date = observable.box(undefined);
this.date.observe(action((chg: IValueDidChange<Date>) => {
const f = format_date(chg.newValue);
this.formatDate.set(f);
// chg.newValue.setHours(0);
// chg.newValue.setMinutes(0);
// chg.newValue.setSeconds(0);
// chg.newValue.setMilliseconds(0);
// console.log('observe fix', chg.newValue);
}));
this.formatDate = observable.box(undefined);
this.formatDate.observe(action((chg: IValueDidChange<string>) => {
this.date.set(new Date(chg.newValue));
}));
action(() => this.formatDate.set(format_date(v)))();
}
示例8: function
ipcMain.on("setMruFilePath", function(event: any, mruItemFilePath: string) {
action(() => {
var i = findMruIndex(mruItemFilePath);
if (i != -1) {
settings.mru.splice(i, 1);
}
settings.mru.unshift({
filePath: mruItemFilePath
});
})();
});
示例9: function
function() {
if (!resizeTimeout) {
resizeTimeout = setTimeout(
action(function() {
resizeTimeout = undefined;
windowSize.width = window.innerWidth;
windowSize.height = window.innerHeight;
}),
10
);
}
},
示例10: dispatch
export default function dispatch(
action: ActionFunction,
actionType: string,
args: IArguments,
actionContext: ActionContext
): void {
getGlobalContext().legacyInDispatch++;
mobxAction(actionType ? actionType : '(anonymous action)', () => {
dispatchWithMiddleware(action, actionType, args, actionContext);
})();
getGlobalContext().legacyInDispatch--;
}
示例11: updateState
function updateState() {
var windowBounds = window.getBounds();
if (!window.isMaximized() && !window.isMinimized() && !window.isFullScreen()) {
normalWindowBounds = Object.assign({}, windowBounds);
}
var displayBounds = screen.getDisplayMatching(windowBounds).bounds;
action(() => {
settings.windowStates[windowId] = {
bounds: normalWindowBounds,
isMaximized: window.isMaximized(),
isFullScreen: window.isFullScreen(),
displayBounds: Object.assign({}, displayBounds)
};
})();
}
示例12: loadSettings
export function loadSettings() {
action(() => {
settings.mru = [];
settings.windowStates = {};
try {
let data = fs.readFileSync(getSettingsFilePath(), "utf8");
try {
let settingsJs: Settings = JSON.parse(data);
if (settingsJs.mru) {
settings.mru = settingsJs.mru.filter((mruItem: IMruItem) =>
fs.existsSync(mruItem.filePath)
);
} else {
settings.mru = [];
}
if (settingsJs.windowStates) {
settings.windowStates = settingsJs.windowStates;
} else {
settings.windowStates = {};
}
settings.dbPath = settingsJs.dbPath;
settings.locale = settingsJs.locale;
settings.dateFormat = settingsJs.dateFormat;
settings.timeFormat = settingsJs.timeFormat;
} catch (parseError) {
console.log(data);
console.error(parseError);
}
} catch (readFileError) {
console.info(`Settings file "${getSettingsFilePath()}" doesn't exists.`);
}
})();
}
示例13: replace
@action('replace message')
replace(text: string, options?: IMessageOptions) {
this.store.remove(this);
this.store.add(text, options);
}
示例14: it
it('date-value round to full day unformated formatDate', () => {
const n = new DateValue(new Date('2018-07-04 17:01:02'), 'what');
action(() => n.formatDate.set('2018-09-04 17:01:03'))();
expect(n.date.get()).toEqual(new Date('2018-09-04'));
expect(n.formatDate.get()).toEqual(format_date(new Date('2018-09-04')));
});
示例15: action
}
return {
hasBinary,
tiers: Object.keys(tiersMap)
};
}
export const initializeCustomDriverAnnotationSettings = action((
report:CustomDriverAnnotationReport,
mutationAnnotationSettings:any,
enableCustomTiers:boolean,
enableOncoKbAndHotspotsIfNoCustomAnnotations:boolean
)=>{
// initialize keys with all available tiers
for (const tier of report.tiers) {
mutationAnnotationSettings.driverTiers.set(tier, enableCustomTiers);
}
if (enableOncoKbAndHotspotsIfNoCustomAnnotations && !report.hasBinary && !report.tiers.length) {
// enable hotspots and oncokb if there are no custom annotations
mutationAnnotationSettings.hotspots = true;
mutationAnnotationSettings.oncoKb = true;
}
});
export function annotateMutationPutativeDriver(
mutation: Mutation,
putativeDriverInfo:{oncoKb:string, hotspots:boolean, cbioportalCount:boolean, cosmicCount:boolean, customDriverBinary:boolean, customDriverTier?:string},
):AnnotatedMutation {
const putativeDriver =
!!(putativeDriverInfo.oncoKb ||