From 6ba7d9ffb0766e9077328389368d09d9b7afd718 Mon Sep 17 00:00:00 2001 From: kPherox Date: Wed, 24 Apr 2019 19:47:26 +0900 Subject: [PATCH] Add extension for map sort by value --- src/components/AddColumn/PublicTimeline.vue | 10 +++++++++- src/extensions/map-sortbyvalue.ts | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/extensions/map-sortbyvalue.ts diff --git a/src/components/AddColumn/PublicTimeline.vue b/src/components/AddColumn/PublicTimeline.vue index f91f7e4a..583dca21 100644 --- a/src/components/AddColumn/PublicTimeline.vue +++ b/src/components/AddColumn/PublicTimeline.vue @@ -14,7 +14,7 @@
{{value.name}} -
{{status.id}}
+
{{status.id}}
void type Instance = string type Timeline = { @@ -61,6 +63,12 @@ export default class AddColumn extends Vue { return this.instance != '' } + public sortedStatus(statuses: Map): Map { + return statuses.sortByValue((s1, s2): number => { + return s1.created_at > s2.created_at ? -1 : 1 + }) + } + public addTL() { let timeline: Timeline = { name: this.instance } diff --git a/src/extensions/map-sortbyvalue.ts b/src/extensions/map-sortbyvalue.ts new file mode 100644 index 00000000..282df10d --- /dev/null +++ b/src/extensions/map-sortbyvalue.ts @@ -0,0 +1,9 @@ + +interface Map { + sortByValue(f: (value1: V, value2: V) => number): Map +} +Map.prototype.sortByValue = function (f: (value1: any, value2: any) => number): Map { + return new Map([...(this as Map)].sort((keyValue1, keyValue2) => { + return f(keyValue1[1], keyValue2[1]); + })) +} \ No newline at end of file