forked from EVOgeek/Vmeda.Online
MOBILE-3947 chore: Deprecate CoreArray.flatten in favor native flat
parent
ccd9c05855
commit
6f371abbdb
|
@ -28,7 +28,6 @@ import {
|
||||||
SUBMISSIONS_GRADES_TABLE,
|
SUBMISSIONS_GRADES_TABLE,
|
||||||
SUBMISSIONS_TABLE,
|
SUBMISSIONS_TABLE,
|
||||||
} from './database/assign';
|
} from './database/assign';
|
||||||
import { CoreArray } from '@singletons/array';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service to handle offline assign.
|
* Service to handle offline assign.
|
||||||
|
@ -87,8 +86,7 @@ export class AddonModAssignOfflineProvider {
|
||||||
|
|
||||||
const results = await Promise.all(promises);
|
const results = await Promise.all(promises);
|
||||||
// Flatten array.
|
// Flatten array.
|
||||||
const flatten = CoreArray
|
const flatten = results.flat();
|
||||||
.flatten<AddonModAssignSubmissionsDBRecordFormatted | AddonModAssignSubmissionsGradingDBRecordFormatted>(results);
|
|
||||||
|
|
||||||
// Get assign id.
|
// Get assign id.
|
||||||
let assignIds: number[] = flatten.map((assign) => assign.assignid);
|
let assignIds: number[] = flatten.map((assign) => assign.assignid);
|
||||||
|
|
|
@ -31,7 +31,6 @@ import { CoreSites } from '@services/sites';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { NgZone, Translate } from '@singletons';
|
import { NgZone, Translate } from '@singletons';
|
||||||
import { CoreArray } from '@singletons/array';
|
|
||||||
import { CoreDom } from '@singletons/dom';
|
import { CoreDom } from '@singletons/dom';
|
||||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
|
@ -826,7 +825,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
|
||||||
protected getAllPosts(): Post[] {
|
protected getAllPosts(): Post[] {
|
||||||
const allPosts = this.posts.map(post => this.flattenPostHierarchy(post));
|
const allPosts = this.posts.map(post => this.flattenPostHierarchy(post));
|
||||||
|
|
||||||
return CoreArray.flatten(allPosts);
|
return allPosts.flat();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -231,7 +231,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
|
||||||
*/
|
*/
|
||||||
private async calculateDownloadedCourseSize(courseId: number): Promise<number> {
|
private async calculateDownloadedCourseSize(courseId: number): Promise<number> {
|
||||||
const sections = await CoreCourse.getSections(courseId);
|
const sections = await CoreCourse.getSections(courseId);
|
||||||
const modules = CoreArray.flatten(sections.map((section) => section.modules));
|
const modules = sections.map((section) => section.modules).flat();
|
||||||
const promisedModuleSizes = modules.map(async (module) => {
|
const promisedModuleSizes = modules.map(async (module) => {
|
||||||
const size = await CoreCourseModulePrefetchDelegate.getModuleStoredSize(module, courseId);
|
const size = await CoreCourseModulePrefetchDelegate.getModuleStoredSize(module, courseId);
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,6 @@ import {
|
||||||
UrlSegmentGroup,
|
UrlSegmentGroup,
|
||||||
} from '@angular/router';
|
} from '@angular/router';
|
||||||
|
|
||||||
import { CoreArray } from '@singletons/array';
|
|
||||||
|
|
||||||
const modulesRoutes: WeakMap<InjectionToken<unknown>, ModuleRoutes> = new WeakMap();
|
const modulesRoutes: WeakMap<InjectionToken<unknown>, ModuleRoutes> = new WeakMap();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,7 +33,7 @@ const modulesRoutes: WeakMap<InjectionToken<unknown>, ModuleRoutes> = new WeakMa
|
||||||
* @returns App routes.
|
* @returns App routes.
|
||||||
*/
|
*/
|
||||||
function buildAppRoutes(injector: Injector): Routes {
|
function buildAppRoutes(injector: Injector): Routes {
|
||||||
return CoreArray.flatten(injector.get<Routes[]>(APP_ROUTES, []));
|
return injector.get<Routes[]>(APP_ROUTES, []).flat();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -210,8 +208,8 @@ export function resolveModuleRoutes(injector: Injector, token: InjectionToken<Mo
|
||||||
});
|
});
|
||||||
|
|
||||||
const moduleRoutes = {
|
const moduleRoutes = {
|
||||||
children: CoreArray.flatten(routes.map(r => r.children)),
|
children: routes.map(r => r.children).flat(),
|
||||||
siblings: CoreArray.flatten(routes.map(r => r.siblings)),
|
siblings: routes.map(r => r.siblings).flat(),
|
||||||
};
|
};
|
||||||
|
|
||||||
modulesRoutes.set(token, moduleRoutes);
|
modulesRoutes.set(token, moduleRoutes);
|
||||||
|
|
|
@ -17,7 +17,6 @@ import { CoreSites } from '@services/sites';
|
||||||
import { CoreTimeUtils } from '@services/utils/time';
|
import { CoreTimeUtils } from '@services/utils/time';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { COMMENTS_TABLE, COMMENTS_DELETED_TABLE, CoreCommentsDBRecord, CoreCommentsDeletedDBRecord } from './database/comments';
|
import { COMMENTS_TABLE, COMMENTS_DELETED_TABLE, CoreCommentsDBRecord, CoreCommentsDeletedDBRecord } from './database/comments';
|
||||||
import { CoreArray } from '@singletons/array';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service to handle offline comments.
|
* Service to handle offline comments.
|
||||||
|
@ -38,7 +37,7 @@ export class CoreCommentsOfflineProvider {
|
||||||
site.getDb().getRecords<CoreCommentsDeletedDBRecord>(COMMENTS_DELETED_TABLE),
|
site.getDb().getRecords<CoreCommentsDeletedDBRecord>(COMMENTS_DELETED_TABLE),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return CoreArray.flatten<CoreCommentsDBRecord | CoreCommentsDeletedDBRecord>(results);
|
return results.flat();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -213,7 +213,7 @@ export class CoreCompileProvider {
|
||||||
|
|
||||||
const lazyImports = await Promise.all(this.LAZY_IMPORTS.map(getModules => getModules()));
|
const lazyImports = await Promise.all(this.LAZY_IMPORTS.map(getModules => getModules()));
|
||||||
const imports = [
|
const imports = [
|
||||||
...CoreArray.flatten(lazyImports),
|
...lazyImports.flat(),
|
||||||
...this.IMPORTS,
|
...this.IMPORTS,
|
||||||
...extraImports,
|
...extraImports,
|
||||||
TranslatePipeForCompile,
|
TranslatePipeForCompile,
|
||||||
|
|
|
@ -41,7 +41,6 @@ import {
|
||||||
CoreCourseSearchedData,
|
CoreCourseSearchedData,
|
||||||
CoreEnrolledCourseData,
|
CoreEnrolledCourseData,
|
||||||
} from '@features/courses/services/courses';
|
} from '@features/courses/services/courses';
|
||||||
import { CoreArray } from '@singletons/array';
|
|
||||||
import { CoreCourseOffline } from './course-offline';
|
import { CoreCourseOffline } from './course-offline';
|
||||||
import {
|
import {
|
||||||
CoreCourseOptionsDelegate,
|
CoreCourseOptionsDelegate,
|
||||||
|
@ -1909,7 +1908,7 @@ export class CoreCourseHelperProvider {
|
||||||
*/
|
*/
|
||||||
async deleteCourseFiles(courseId: number): Promise<void> {
|
async deleteCourseFiles(courseId: number): Promise<void> {
|
||||||
const sections = await CoreCourse.getSections(courseId);
|
const sections = await CoreCourse.getSections(courseId);
|
||||||
const modules = CoreArray.flatten(sections.map((section) => section.modules));
|
const modules = sections.map((section) => section.modules).flat();
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
modules.map((module) => this.removeModuleStoredData(module, courseId)),
|
modules.map((module) => this.removeModuleStoredData(module, courseId)),
|
||||||
|
|
|
@ -19,7 +19,6 @@ import { CoreSites } from '@services/sites';
|
||||||
import { CoreConstants } from '@/core/constants';
|
import { CoreConstants } from '@/core/constants';
|
||||||
import { CoreMainMenuDelegate, CoreMainMenuHandlerToDisplay } from './mainmenu-delegate';
|
import { CoreMainMenuDelegate, CoreMainMenuHandlerToDisplay } from './mainmenu-delegate';
|
||||||
import { Device, makeSingleton } from '@singletons';
|
import { Device, makeSingleton } from '@singletons';
|
||||||
import { CoreArray } from '@singletons/array';
|
|
||||||
import { CoreTextUtils } from '@services/utils/text';
|
import { CoreTextUtils } from '@services/utils/text';
|
||||||
import { CoreScreen } from '@services/screen';
|
import { CoreScreen } from '@services/screen';
|
||||||
import { CorePlatform } from '@services/platform';
|
import { CorePlatform } from '@services/platform';
|
||||||
|
@ -73,7 +72,7 @@ export class CoreMainMenuProvider {
|
||||||
this.getCustomItemsFromConfig(),
|
this.getCustomItemsFromConfig(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return CoreArray.flatten(customItems);
|
return customItems.flat();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,7 +41,6 @@ import {
|
||||||
SiteDBEntry,
|
SiteDBEntry,
|
||||||
SchemaVersionsDBEntry,
|
SchemaVersionsDBEntry,
|
||||||
} from '@services/database/sites';
|
} from '@services/database/sites';
|
||||||
import { CoreArray } from '../singletons/array';
|
|
||||||
import { CoreNetworkError } from '@classes/errors/network-error';
|
import { CoreNetworkError } from '@classes/errors/network-error';
|
||||||
import { CoreNavigator, CoreRedirectPayload } from './navigator';
|
import { CoreNavigator, CoreRedirectPayload } from './navigator';
|
||||||
import { CoreSitesFactory } from './sites-factory';
|
import { CoreSitesFactory } from './sites-factory';
|
||||||
|
@ -98,7 +97,7 @@ export class CoreSitesProvider {
|
||||||
|
|
||||||
constructor(@Optional() @Inject(CORE_SITE_SCHEMAS) siteSchemas: CoreSiteSchema[][] | null) {
|
constructor(@Optional() @Inject(CORE_SITE_SCHEMAS) siteSchemas: CoreSiteSchema[][] | null) {
|
||||||
this.logger = CoreLogger.getInstance('CoreSitesProvider');
|
this.logger = CoreLogger.getInstance('CoreSitesProvider');
|
||||||
this.siteSchemas = CoreArray.flatten(siteSchemas ?? []).reduce(
|
this.siteSchemas = (siteSchemas ?? []).flat().reduce(
|
||||||
(siteSchemas, schema) => {
|
(siteSchemas, schema) => {
|
||||||
siteSchemas[schema.name] = schema;
|
siteSchemas[schema.name] = schema;
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,13 @@ export class CoreArray {
|
||||||
*
|
*
|
||||||
* @param arr Original array.
|
* @param arr Original array.
|
||||||
* @returns Flattened array.
|
* @returns Flattened array.
|
||||||
|
* @deprecated since 4.4 Use Array.prototype.flat() instead.
|
||||||
*/
|
*/
|
||||||
static flatten<T>(arr: T[][]): T[] {
|
static flatten<T>(arr: T[][]): T[] {
|
||||||
return (<T[]> []).concat(...arr);
|
// eslint-disable-next-line no-console
|
||||||
|
console.warn('CoreArray.flatten is deprecated and will be removed soon. Please use array \'flat\' instead.');
|
||||||
|
|
||||||
|
return arr.flat();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,11 +16,6 @@ import { CoreArray } from '@singletons/array';
|
||||||
|
|
||||||
describe('CoreArray singleton', () => {
|
describe('CoreArray singleton', () => {
|
||||||
|
|
||||||
it('flattens arrays', () => {
|
|
||||||
expect(CoreArray.flatten([])).toEqual([]);
|
|
||||||
expect(CoreArray.flatten<number>([[1, 2], [3, 4], [5, 6]])).toEqual([1, 2, 3, 4, 5, 6]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('gets array without an item', () => {
|
it('gets array without an item', () => {
|
||||||
const originalArray = ['foo', 'bar', 'baz'];
|
const originalArray = ['foo', 'bar', 'baz'];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue