@sankhyalabs/core
Advanced tools
Comparing version 1.0.38 to 1.0.39
@@ -13,2 +13,3 @@ import { UnitMetadata, FieldDescriptor, SortingProvider, FilterProvider, Sort, Filter } from "./metadata/UnitMetadata"; | ||
saveLoader?: (dataUnit: DataUnit, changes: Array<Change>) => Promise<Array<SavedRecord>>; | ||
removeLoader?: (dataUnit: DataUnit, recordIds: Array<string>) => Promise<Array<string>>; | ||
constructor(name: string); | ||
@@ -22,2 +23,4 @@ get name(): string; | ||
saveData(): Promise<void>; | ||
removeSelectedRecords(buffered?: boolean): Promise<Array<string>>; | ||
removeRecords(records: Array<string>, buffered?: boolean): Promise<Array<string>>; | ||
valueFromString(fieldName: string, value: string): any; | ||
@@ -34,3 +37,2 @@ addInterceptor(interceptor: DUActionInterceptor): void; | ||
copySelected(): void; | ||
removeSelectedRecords(): void; | ||
getFieldValue(fieldName: string): any; | ||
@@ -37,0 +39,0 @@ setFieldValue(fieldName: string, newValue: any, records?: Array<string>): void; |
@@ -104,2 +104,32 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
removeSelectedRecords(buffered = false) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const selection = getSelection(this._stateManager); | ||
if (selection) { | ||
return this.removeRecords(selection, buffered); | ||
} | ||
return Promise.resolve(selection); | ||
}); | ||
} | ||
removeRecords(records, buffered = false) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (records) { | ||
if (buffered || !this.removeLoader) { | ||
this.dispatchAction(Action.RECORDS_REMOVED, { records, buffered: true }); | ||
} | ||
else { | ||
this.dispatchAction(Action.REMOVING_RECORDS); | ||
return new Promise((resolve, fail) => { | ||
if (this.removeLoader) { | ||
this.removeLoader(this, records).then(records => { | ||
this.dispatchAction(Action.RECORDS_REMOVED, { records, buffered: false }); | ||
resolve(records); | ||
}).catch(error => fail(error)); | ||
} | ||
}); | ||
} | ||
} | ||
return Promise.resolve(records); | ||
}); | ||
} | ||
// API | ||
@@ -144,8 +174,2 @@ valueFromString(fieldName, value) { | ||
} | ||
removeSelectedRecords() { | ||
const selection = getSelection(this._stateManager); | ||
if (selection) { | ||
this.dispatchAction(Action.RECORDS_REMOVED, selection); | ||
} | ||
} | ||
getFieldValue(fieldName) { | ||
@@ -152,0 +176,0 @@ return getFieldValue(this._stateManager, fieldName); |
@@ -16,2 +16,3 @@ import { StateAction } from "../StateManager"; | ||
DATA_SAVED = "dataSaved", | ||
REMOVING_RECORDS = "removingRecords", | ||
RECORDS_REMOVED = "recordsRemoved", | ||
@@ -18,0 +19,0 @@ RECORDS_ADDED = "recordsAdded", |
@@ -21,2 +21,3 @@ export class DataUnitAction { | ||
Action["DATA_SAVED"] = "dataSaved"; | ||
Action["REMOVING_RECORDS"] = "removingRecords"; | ||
Action["RECORDS_REMOVED"] = "recordsRemoved"; | ||
@@ -23,0 +24,0 @@ Action["RECORDS_ADDED"] = "recordsAdded"; |
@@ -11,2 +11,8 @@ import { Action } from "../action/DataUnitAction"; | ||
return action.payload; | ||
case Action.RECORDS_REMOVED: | ||
const { records, buffered } = action.payload; | ||
if (!buffered) { | ||
return currentState.filter(r => !records.includes(r.__record__id__)); | ||
} | ||
return currentState; | ||
case Action.DATA_SAVED: | ||
@@ -13,0 +19,0 @@ const recordsMap = new Map(); |
@@ -9,3 +9,7 @@ import { Action } from "../action/DataUnitAction"; | ||
case Action.RECORDS_REMOVED: | ||
return (currentState || []).concat(action.payload); | ||
const { records, buffered } = action.payload; | ||
if (buffered) { | ||
return (currentState || []).concat(records); | ||
} | ||
return currentState; | ||
case Action.EDITION_CANCELED: | ||
@@ -12,0 +16,0 @@ case Action.DATA_SAVED: |
@@ -15,3 +15,3 @@ import { Action } from "../action/DataUnitAction"; | ||
case Action.RECORDS_REMOVED: | ||
const removed = action.payload; | ||
const removed = action.payload.records; | ||
if (currentState && removed) { | ||
@@ -18,0 +18,0 @@ return currentState.filter(recordId => !removed.includes(recordId)); |
export default class ApplicationContext { | ||
static getContextValue(key) { | ||
return ApplicationContext.getCtx()[key].deref(); | ||
const weakRef = ApplicationContext.getCtx()[key]; | ||
return weakRef ? weakRef.deref() : undefined; | ||
} | ||
@@ -5,0 +6,0 @@ static setContextValue(key, value) { |
{ | ||
"name": "@sankhyalabs/core", | ||
"version": "1.0.38", | ||
"version": "1.0.39", | ||
"description": "Modulo core JavaScript da Sankhya.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -28,2 +28,3 @@ import { UnitMetadata, FieldDescriptor, SortingProvider, FilterProvider, Sort, Filter } from "./metadata/UnitMetadata"; | ||
public saveLoader?: (dataUnit: DataUnit, changes: Array<Change>) => Promise<Array<SavedRecord>>; | ||
public removeLoader?: (dataUnit: DataUnit, recordIds: Array<string>) => Promise<Array<string>>; | ||
@@ -124,2 +125,31 @@ constructor(name: string) { | ||
public async removeSelectedRecords(buffered: boolean = false): Promise<Array<string>> { | ||
const selection = getSelection(this._stateManager); | ||
if (selection) { | ||
return this.removeRecords(selection, buffered); | ||
} | ||
return Promise.resolve(selection); | ||
} | ||
public async removeRecords(records:Array<string>, buffered: boolean = false): Promise<Array<string>> { | ||
if (records) { | ||
if (buffered || !this.removeLoader) { | ||
this.dispatchAction(Action.RECORDS_REMOVED, { records, buffered: true }); | ||
} else { | ||
this.dispatchAction(Action.REMOVING_RECORDS); | ||
return new Promise((resolve, fail) => { | ||
if (this.removeLoader) { | ||
this.removeLoader(this, records).then( | ||
records => { | ||
this.dispatchAction(Action.RECORDS_REMOVED, { records, buffered: false }); | ||
resolve(records); | ||
} | ||
).catch(error => fail(error)); | ||
} | ||
}); | ||
} | ||
} | ||
return Promise.resolve(records); | ||
} | ||
// API | ||
@@ -168,5 +198,5 @@ public valueFromString(fieldName: string, value: string): any { | ||
public copySelected(): void{ | ||
public copySelected(): void { | ||
const selectedRecords = this.getSelectedRecords(); | ||
if(selectedRecords){ | ||
if (selectedRecords) { | ||
this.dispatchAction(Action.RECORDS_COPIED, prepareAddedRecordId(this._stateManager, selectedRecords)); | ||
@@ -176,9 +206,2 @@ } | ||
public removeSelectedRecords(): void { | ||
const selection = getSelection(this._stateManager); | ||
if (selection) { | ||
this.dispatchAction(Action.RECORDS_REMOVED, selection); | ||
} | ||
} | ||
public getFieldValue(fieldName: string): any { | ||
@@ -210,5 +233,5 @@ return getFieldValue(this._stateManager, fieldName); | ||
public getSelectedRecords(): Array<Record>|undefined{ | ||
public getSelectedRecords(): Array<Record> | undefined { | ||
const selection: Array<string> = this.getSelection(); | ||
if(selection){ | ||
if (selection) { | ||
const currentRecords: Array<Record> = this.records; | ||
@@ -259,3 +282,3 @@ return currentRecords?.filter(r => selection.includes(r.__record__id__)); | ||
public toString(){ | ||
public toString() { | ||
return this.name; | ||
@@ -269,3 +292,3 @@ } | ||
this._interceptors?.forEach(interceptor => { | ||
if(action){ | ||
if (action) { | ||
action = interceptor.interceptAction(action); | ||
@@ -275,3 +298,3 @@ } | ||
if(action){ | ||
if (action) { | ||
this._stateManager.process(action); | ||
@@ -291,4 +314,4 @@ this._observers.forEach(f => f(action)); | ||
export interface DUActionInterceptor{ | ||
interceptAction(action: DataUnitAction): DataUnitAction; | ||
export interface DUActionInterceptor { | ||
interceptAction(action: DataUnitAction): DataUnitAction; | ||
} | ||
@@ -327,3 +350,3 @@ | ||
public get operation(): string{ | ||
public get operation(): string { | ||
return this._operation.toString(); | ||
@@ -330,0 +353,0 @@ } |
@@ -34,3 +34,5 @@ | ||
REMOVING_RECORDS = "removingRecords", | ||
RECORDS_REMOVED = "recordsRemoved", | ||
RECORDS_ADDED = "recordsAdded", | ||
@@ -37,0 +39,0 @@ RECORDS_COPIED = "recordsCopied", |
@@ -18,3 +18,10 @@ | ||
return action.payload; | ||
case Action.RECORDS_REMOVED: | ||
const {records, buffered} = action.payload; | ||
if(!buffered){ | ||
return currentState.filter(r=>!records.includes(r.__record__id__)); | ||
} | ||
return currentState; | ||
case Action.DATA_SAVED: | ||
@@ -21,0 +28,0 @@ |
@@ -13,3 +13,7 @@ | ||
case Action.RECORDS_REMOVED: | ||
return (currentState||[]).concat(action.payload); | ||
const {records, buffered} = action.payload; | ||
if(buffered){ | ||
return (currentState||[]).concat(records); | ||
} | ||
return currentState; | ||
case Action.EDITION_CANCELED: | ||
@@ -16,0 +20,0 @@ case Action.DATA_SAVED: |
@@ -21,3 +21,3 @@ import { ActionReducer, StateAction } from "../StateManager"; | ||
case Action.RECORDS_REMOVED: | ||
const removed: Array<string> = action.payload; | ||
const removed: Array<string> = action.payload.records; | ||
if (currentState && removed) { | ||
@@ -24,0 +24,0 @@ return currentState.filter(recordId => !removed.includes(recordId)) |
export default class ApplicationContext{ | ||
public static getContextValue(key: string):any{ | ||
return ApplicationContext.getCtx()[key].deref(); | ||
const weakRef = ApplicationContext.getCtx()[key]; | ||
return weakRef ? weakRef.deref() : undefined; | ||
} | ||
@@ -6,0 +7,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
294884
5670