Skip to content

Commit

Permalink
Upgrade the payload saving in the TransferStateService #5
Browse files Browse the repository at this point in the history
  • Loading branch information
athlonUA committed Aug 16, 2018
1 parent 1a547d0 commit aac5f26
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ export class DocumentLinkService {
public addTags(tags: LinkDefinition[]): void {
this.transferStateService
.savePayload(
() => {
tags.map((tag: LinkDefinition) => this.addTag(tag));
() =>
new Promise(resolve => {
tags.map((tag: LinkDefinition) => this.addTag(tag));
const payload = { addTagsExecuted: true };

return new Promise(resolve => resolve({ payload: { addTagsExecuted: true } }));
},
this.payloadServerName,
{ payload: null }
resolve({ payload });
}),
this.payloadServerName
)
.then(
(payload: PayloadDefinition) => {
Expand All @@ -58,13 +59,14 @@ export class DocumentLinkService {
public removeTags(attrSelectors: string[]): void {
this.transferStateService
.savePayload(
() => {
attrSelectors.map((attrSelector: string) => this.removeTag(attrSelector));
() =>
new Promise(resolve => {
attrSelectors.map((attrSelector: string) => this.removeTag(attrSelector));
const payload = { removeTagsExecuted: true };

return new Promise(resolve => resolve({ payload: { removeTagsExecuted: true } }));
},
this.payloadServerName,
{ payload: null }
resolve({ payload });
}),
this.payloadServerName
)
.then(
(payload: PayloadDefinition) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ export class DocumentMetaService {
public addTags(tags: MetaDefinition[], forceCreation: boolean = false): void {
this.transferStateService
.savePayload(
() => {
this.metaService.addTags(tags, forceCreation);
() =>
new Promise(resolve => {
this.metaService.addTags(tags, forceCreation);
const payload = { addTagsExecuted: true };

return new Promise(resolve => resolve({ payload: { addTagsExecuted: true } }));
},
this.payloadServerName,
{ payload: null }
resolve({ payload });
}),
this.payloadServerName
)
.then(
(payload: PayloadDefinition) => {
Expand All @@ -44,13 +45,14 @@ export class DocumentMetaService {
public removeTags(attrSelectors: string[]): void {
this.transferStateService
.savePayload(
() => {
attrSelectors.map((attrSelector: string) => this.removeTag(attrSelector));
() =>
new Promise(resolve => {
attrSelectors.map((attrSelector: string) => this.removeTag(attrSelector));
const payload = { removeTagsExecuted: true };

return new Promise(resolve => resolve({ payload: { removeTagsExecuted: true } }));
},
this.payloadServerName,
{ payload: null }
resolve({ payload });
}),
this.payloadServerName
)
.then(
(payload: PayloadDefinition) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ export class DocumentTitleService {
public setTitle(value: string): void {
this.transferStateService
.savePayload(
() => {
this.titleService.setTitle(value);
() =>
new Promise(resolve => {
this.titleService.setTitle(value);
const payload = { setTitleExecuted: true };

return new Promise(resolve => resolve({ payload: { setTitleExecuted: true } }));
},
this.payloadServerName,
{ payload: null }
resolve({ payload });
}),
this.payloadServerName
)
.then(
(payload: PayloadDefinition) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ export class HttpResponseStatusService {
public setStatus(code: number, message: string): void {
this.transferStateService
.savePayload(
() => {
if (this.res) {
this.res.statusCode = code;
this.res.statusMessage = message;
}
() =>
new Promise(resolve => {
if (this.res) {
this.res.statusCode = code;
this.res.statusMessage = message;
}

return new Promise(resolve => resolve({ payload: { setStatusExecuted: true } }));
},
this.payloadServerName,
{ payload: null }
const payload = { setStatusExecuted: true };

resolve({ payload });
}),
this.payloadServerName
)
.then(
(payload: PayloadDefinition) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export class TransferStateService {

constructor(@Inject(PLATFORM_ID) private platformId: Object, private transferState: TransferState) {}

public savePayload(next: () => Promise<any>, payloadServerName: string, defaultPayload: any): Promise<any> {
public savePayload(next: () => Promise<any>, payloadServerName: string): Promise<any> {
const defaultPayload = { payload: null };
const payloadStateKey = this.createStateKey(payloadServerName);

return new Promise(resolve => {
Expand Down

0 comments on commit aac5f26

Please sign in to comment.