mobx#transaction TypeScript Examples
The following examples show how to use
mobx#transaction.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: equip_embed.tsx From j3pz-web with MIT License | 6 votes |
setEmbed = (idx: number, level: number) => {
const { store } = this.props;
const currentEquip = store.equips[store.activeEquipNav];
if (currentEquip) {
transaction(() => {
store.equips[store.activeEquipNav] = currentEquip.setEmbed(idx, level);
EmbedService.update(store);
});
}
};
Example #2
Source File: Prompts.Client.ts From companion-kit with MIT License | 6 votes |
private processState = async (clientPrompts: ClientLibraryStateIded) => {
if (clientPrompts == null) {
clientPrompts = {
id: this.clientUid,
};
}
transaction(() => {
ClientLibraryState.migrate(clientPrompts, true);
this._state = clientPrompts;
this._promptsActivity.setItems(this._state.prompts);
});
await this.setDefaultData(clientPrompts);
}
Example #3
Source File: school_dropdown.tsx From j3pz-web with MIT License | 6 votes |
changeSchool = (value: KungFu) => {
const { store } = this.props;
store.kungfuMeta = null;
transaction(() => {
KungFuService.getKungFu(value).then((res) => {
store.kungfu = value;
store.kungfuMeta = res.attributes;
});
});
};
Example #4
Source File: ClientEditorViewModel.ts From companion-kit with MIT License | 6 votes |
constructor() {
this._unsubscribe = reaction(_ => this.client, c => {
transaction(() => {
if (!c || !c.id) {
this.resetAllFields();
} else {
this._fillUserInfo();
}
});
});
}
Example #5
Source File: equip_selection.tsx From j3pz-web with MIT License | 6 votes |
setEquip = (value: number) => {
const { store } = this.props;
const currentPosition = store.activeEquipNav;
EquipService.getEquip(value).then((res) => {
const equip = Equip.fromJson(res.attributes);
transaction(() => {
let finalEquip = equip;
const oldEquip = store.equips[currentPosition];
if (oldEquip && oldEquip.strengthLevel < oldEquip.strengthen) {
finalEquip = finalEquip.setStrengthLevel(oldEquip.strengthLevel);
} else if (store.settings.autoStrengthen) {
finalEquip = finalEquip.setStrengthLevel(equip.strengthen);
}
if (oldEquip?.enhance) {
finalEquip = finalEquip.setEnhance(oldEquip.enhance);
}
const level = store.settings.autoEmbed;
finalEquip = finalEquip.setEmbed(0, oldEquip?.embedding[0]?.level ?? level)
.setEmbed(1, oldEquip?.embedding[1]?.level ?? level)
.setEmbed(2, oldEquip?.embedding[2]?.level ?? level);
store.equips[currentPosition] = finalEquip;
CollectionService.updateCollection(store);
EmbedService.update(store);
});
});
};
Example #6
Source File: Documents.ts From companion-kit with MIT License | 6 votes |
markAsOpened = async (docId: string) => {
const doc = this.activeLinks.find(d => d.id === docId);
if (!doc) {
throw new Error('Link Doc was not found for id = ' + docId);
}
const prevStatus = doc.share.status;
transaction(() => {
doc.share.status = DocumentLinkShareStatuses.Opened;
if (this._seendDocsIds[doc.id]) {
delete this._seendDocsIds[doc.id];
this.saveSeenIds();
}
});
try {
await Firebase.Instance.getFunction(CoachesFunctions.MarkDocumentLinkAsSeen)
.execute({
coachId: this.coachId,
clientCardId: this.clientCardId,
documentId: docId,
status: DocumentLinkShareStatuses.Opened,
});
} catch (err) {
doc.share.status = prevStatus;
throw err;
}
}
Example #7
Source File: case_settings.tsx From j3pz-web with MIT License | 6 votes |
embedAll = () => {
const { store } = this.props;
transaction(() => {
Object.entries(store.equips).forEach(([key, equip]) => {
[0, 1, 2].forEach((n) => {
if ((equip?.embedding[n]?.level ?? 0) < store.settings.autoEmbed) {
store.equips[key] = store.equips[key]?.setEmbed(n, store.settings.autoEmbed);
}
});
});
EmbedService.update(store);
Alert.success('精炼已完成');
});
};
Example #8
Source File: AssessmentItemViewModel.ts From companion-kit with MIT License | 6 votes |
private chooseAnswer(answerIndex: number, route?: number) {
// save current question index to history
this.previousSteps.push(this.stepIndex);
// save the answer
this.completedAnswers[this.completedAnswers.length] = answerIndex;
transaction(() => {
if (route === null) {
// non-linear: finish
this.stepIndex = this.questions.length;
} else if (route) {
// non-linear: route to the next question
this.stepIndex = route;
} else {
// linear: go to the next question
this.stepIndex += 1;
}
if (this.isFinalScreen) {
// temporary result that can be used on the final screen
// will be overwritten after form submit
this.formResult = {
id: 'temp-client-generated',
formType: this.formType || null,
answers: this.completedAnswers,
};
}
});
}
Example #9
Source File: case_settings.tsx From j3pz-web with MIT License | 6 votes |
setStrenthenForAll = () => {
const { store } = this.props;
transaction(() => {
Object.entries(store.equips).forEach(([key, equip]) => {
store.equips[key] = equip?.setStrengthLevel(equip.strengthen);
});
Alert.success('精炼已完成');
});
};
Example #10
Source File: CheckInViewModel.ts From companion-kit with MIT License | 6 votes |
public updateAudioUrl() {
if (this._urlObserver) {
return;
}
this._urlObserver = reaction(_ => this.audioUrl, url => {
transaction(() => {
this._audioPlayer?.reset();
if (url) {
logger.log('[CheckInViewModel] setting audio url', this.audioRef, ' ====> ', url);
this._audioPlayer = new AudioPlayerViewModel();
this._audioPlayer.url = url;
this._audioPlayer.setup();
}
});
});
}
Example #11
Source File: verify.tsx From j3pz-web with MIT License | 6 votes |
componentDidMount() {
const permalink = getUrlParameter('permalink');
const token = getUrlParameter('token');
if (permalink && token) {
UserService.verify(permalink, token).then((res) => {
if (res.attributes) {
transaction(() => {
const user = User.fromJson(res.attributes);
$store.user = user;
localStorage.setItem('token', user.token);
});
this.setState({ pending: false, valid: true });
setTimeout(() => {
navigate('/dashboard');
}, 3000);
} else {
this.setState({ pending: false, valid: false });
}
});
} else {
this.setState({ pending: false, valid: false });
}
}
Example #12
Source File: SignInViewModel.ts From companion-kit with MIT License | 6 votes |
reset() {
this.Storage.remove(NewPasswordKey);
transaction(() => {
this.email.reset();
this.password.reset();
this._error = null;
this._needsOldPassword = false;
});
}
Example #13
Source File: edit.tsx From j3pz-web with MIT License | 5 votes |
componentDidMount() {
const caseId = window.location.hash.replace('#', '');
if (caseId) {
CaseService.getCase(caseId).then((res) => {
if (res) {
const detail = CaseDetail.fromJson(res.attributes);
CaseService.applyToStore(detail);
EmbedService.update($store);
} else {
navigate('/dashboard');
}
});
} else {
Alert.warning('这是一个临时界面,配装方案仅能在当前设备上进行修改而无法保存。', 10000);
}
if (!this.props.store.user) {
UserService.getUser(false).then((res) => {
if (res) {
transaction(() => {
$store.user = User.fromJson(res.attributes);
$store.settings.autoStrengthen = !!res.attributes.preference.strengthen;
$store.settings.autoEmbed = res.attributes.preference.magicStoneLevel;
});
}
});
}
SettingsService.getAnnouncement().then((res) => {
const checkedVersion = localStorage.getItem('announcement');
if (res?.version && res?.version !== checkedVersion) {
Notification.open({
key: 'announcement',
title: res.title ?? '公告',
description: res.content,
duration: 0,
placement: 'bottomEnd',
});
localStorage.setItem('announcement', res.version);
}
});
}
Example #14
Source File: CreateCheckInViewModel.ts From companion-kit with MIT License | 5 votes |
public rollQuestion = () => {
transaction(() => {
this._keptQuestion = null;
this._questions?.roll();
});
MobileTracker.Instance?.trackEvent(Events.PromptShuffle);
}