🎨 add getAllTags & remove polyfill
This commit is contained in:
@@ -1,27 +1,13 @@
|
|||||||
import resources from '../resources'
|
import resources from '../resources'
|
||||||
import * as R from 'ramda'
|
import * as R from 'ramda'
|
||||||
import { includesElOf, getAllResources, tagsNotEmpty, partiallyIncludesElOf, cleanString } from '../utils/pure'
|
import {
|
||||||
|
getAllResources,
|
||||||
// Polyfill for flat
|
getAllTags,
|
||||||
if (!Array.prototype.flat) {
|
includesElOf,
|
||||||
Object.defineProperty(Array.prototype, 'flat', {
|
partiallyIncludesElOf,
|
||||||
configurable: true,
|
tagsNotEmpty,
|
||||||
value: function flat () {
|
cleanString,
|
||||||
var depth = isNaN(arguments[0]) ? 1 : Number(arguments[0])
|
} from '../utils/pure'
|
||||||
|
|
||||||
return depth ? Array.prototype.reduce.call(this, function (acc, cur) {
|
|
||||||
if (Array.isArray(cur)) {
|
|
||||||
acc.push.apply(acc, flat.call(cur, depth - 1))
|
|
||||||
} else {
|
|
||||||
acc.push(cur)
|
|
||||||
}
|
|
||||||
|
|
||||||
return acc
|
|
||||||
}, []) : Array.prototype.slice.call(this)
|
|
||||||
},
|
|
||||||
writable: true,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export const state = () => ({
|
export const state = () => ({
|
||||||
resources: resources.map(category => ({
|
resources: resources.map(category => ({
|
||||||
@@ -36,11 +22,7 @@ export const state = () => ({
|
|||||||
}),
|
}),
|
||||||
})),
|
})),
|
||||||
// List of all tags, duplicates removed
|
// List of all tags, duplicates removed
|
||||||
tags: [...new Set(
|
tags: getAllTags(resources),
|
||||||
resources
|
|
||||||
.map(resource => resource.resources).flat()
|
|
||||||
.map(resource => resource.tags).flat()
|
|
||||||
)],
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getters = {
|
export const getters = {
|
||||||
@@ -49,7 +31,7 @@ export const getters = {
|
|||||||
findCategory: state => categoryTitle => {
|
findCategory: state => categoryTitle => {
|
||||||
// equalsCategoryTitle :: Category -> Bool
|
// equalsCategoryTitle :: Category -> Bool
|
||||||
const equalsCategoryTitle = R.compose(
|
const equalsCategoryTitle = R.compose(
|
||||||
R.equals(R.toLower(categoryTitle)), R.toLower, R.prop('title')
|
R.equals(cleanString(categoryTitle)), cleanString, R.prop('title')
|
||||||
)
|
)
|
||||||
// findCategory :: [Category] -> Category
|
// findCategory :: [Category] -> Category
|
||||||
const findCategory = R.find(equalsCategoryTitle)
|
const findCategory = R.find(equalsCategoryTitle)
|
||||||
|
|||||||
@@ -24,6 +24,14 @@ export const isNotEmpty = R.compose(R.not, R.isEmpty)
|
|||||||
// getAllResources :: [Category] -> [Resource]
|
// getAllResources :: [Category] -> [Resource]
|
||||||
export const getAllResources = R.compose(R.flatten, R.map(R.prop('resources')))
|
export const getAllResources = R.compose(R.flatten, R.map(R.prop('resources')))
|
||||||
|
|
||||||
|
// getAllTags :: [Category] -> [String]
|
||||||
|
export const getAllTags = R.compose(
|
||||||
|
R.uniq,
|
||||||
|
R.flatten,
|
||||||
|
R.map(R.prop('tags')),
|
||||||
|
getAllResources
|
||||||
|
)
|
||||||
|
|
||||||
// tagsNotEmpty :: Resource -> Bool
|
// tagsNotEmpty :: Resource -> Bool
|
||||||
export const tagsNotEmpty = R.compose(isNotEmpty, R.prop('tags'))
|
export const tagsNotEmpty = R.compose(isNotEmpty, R.prop('tags'))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user