Skip to content

Commit 73fc88b

Browse files
committed
[fix] getAll method
The array will be sorted if an ordering function is provided.
1 parent c8e8679 commit 73fc88b

File tree

9 files changed

+27
-22
lines changed

9 files changed

+27
-22
lines changed

README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Note
2+
This project is a fork of the project of [Manu Bhardwaj](https://github.com/imanubhardwaj),
3+
You can access the original project [here](https://github.com/imanubhardwaj/vue-entity-adapter).
4+
5+
6+
The difference from this project to the original project, are just a few changes in the definitions for typescript and a small improvement in the ordering logic in the getAll method.
7+
18
# Introduction
29

310
Entity State adapter for managing record collections.
@@ -15,11 +22,7 @@ Extensible type-safe adapters for selecting entity information.
1522
## Installation
1623
Installing with *npm*
1724

18-
``npm i vue-entity-adapter``
19-
20-
Installing with *yarn*
21-
22-
``yarn add vue-entity-adapter``
25+
``npm i vue-entity-adapter-plus``
2326

2427
## Getting Started
2528

example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"core-js": "^2.6.5",
1212
"vue": "^2.6.10",
1313
"vue-class-component": "^7.0.2",
14-
"vue-entity-adapter": "^1.0.2",
14+
"vue-entity-adapter-plus": "^1.0.0",
1515
"vue-property-decorator": "^8.1.0",
1616
"vuex": "^3.0.1"
1717
},

example/src/models/state.model.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {EntityState} from "vue-entity-adapter";
1+
import {EntityState} from "vue-entity-adapter-plus";
22
import {Lesson} from "@/models/lessons.model";
33

44
export interface State {

example/src/store.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Vue from 'vue'
22
import Vuex from 'vuex'
33
import {Lesson} from "@/models/lessons.model"
4-
import {EntityAdapter} from 'vue-entity-adapter'
4+
import {EntityAdapter} from 'vue-entity-adapter-plus'
55
import actions from '@/store/actions';
66
import mutations from '@/store/mutations';
77
import getters from '@/store/getters';

example/src/store/actions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
UPDATE_LESSONS_MUTATION, UPSERT_LESSON_ACTION, UPSERT_LESSON_MUTATION, UPSERT_LESSONS_ACTION, UPSERT_LESSONS_MUTATION
1717
} from "@/store/types";
1818
import {Lesson} from "@/models/lessons.model";
19-
import {Update} from "vue-entity-adapter";
19+
import {Update} from "vue-entity-adapter-plus";
2020

2121
export default {
2222
[ADD_LESSON_ACTION]: ({commit}: any, payload: Lesson) => {

example/src/store/mutations.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import {State} from "@/models/state.model";
1515
import {Lesson} from "@/models/lessons.model";
1616
import {lessonsAdapter} from "@/store";
17-
import {Update} from "vue-entity-adapter";
17+
import {Update} from "vue-entity-adapter-plus";
1818

1919
export default {
2020
[ADD_LESSON_MUTATION]: (state: State, payload: Lesson) => {

index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="node" />
22

3-
declare module 'vue-entity-adapter' {
3+
declare module 'vue-entity-adapter-plus' {
44
export interface EntityState<T> {
55
ids: string[];
66
entities: T[];

index.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cloneDeep } from 'lodash';
1+
import { cloneDeep } from "lodash";
22

33
/**
44
* Class to manipulate entities
@@ -17,8 +17,8 @@ export class EntityAdapter {
1717
getInitialState() {
1818
return {
1919
ids: this.ids,
20-
entities: this.entities
21-
}
20+
entities: this.entities,
21+
};
2222
}
2323

2424
/**
@@ -37,7 +37,9 @@ export class EntityAdapter {
3737
* @returns {(*)[]}
3838
*/
3939
getAll(state) {
40-
return Object.keys(state.entities).map(key => state.entities[key]).sort(this.sortFn);
40+
return this.sortFn
41+
? Object.keys(state.entities).map((key) => state.entities[key]).sort(this.sortFn)
42+
: Object.keys(state.entities).map((key) => state.entities[key]);
4143
}
4244

4345
/**
@@ -116,7 +118,7 @@ export class EntityAdapter {
116118
const newState = cloneDeep(state);
117119

118120
delete newState.entities[id];
119-
newState.ids = newState.ids.filter(_id => _id !== id);
121+
newState.ids = newState.ids.filter((_id) => _id !== id);
120122

121123
return newState;
122124
}
@@ -193,7 +195,7 @@ export class EntityAdapter {
193195
let newState = cloneDeep(state);
194196

195197
if (element.id in newState.entities) {
196-
newState = this.updateOne({id: element.id, changes: element}, newState);
198+
newState = this.updateOne({ id: element.id, changes: element }, newState);
197199
} else {
198200
newState = this.addOne(element, newState);
199201
}

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "vue-entity-adapter",
3-
"version": "1.0.5",
2+
"name": "vue-entity-adapter-plus",
3+
"version": "1.0.0",
44
"description": "Package to maintain entities for vuex.",
55
"private": false,
66
"keywords": ["Vue", "Vuex", "State Management", "Entity Adapter", "Flux"],
@@ -11,14 +11,14 @@
1111
},
1212
"repository": {
1313
"type": "git",
14-
"url": "git+https://github.com/imanubhardwaj/vue-entity-adapter.git"
14+
"url": "git+https://github.com/sandrohaiden/vue-entity-adapter-plus.git"
1515
},
1616
"author": "Manu Bhardwaj",
1717
"license": "MIT",
1818
"bugs": {
19-
"url": "https://github.com/imanubhardwaj/vue-entity-adapter/issues"
19+
"url": "https://github.com/sandrohaiden/vue-entity-adapter-plus/issues"
2020
},
21-
"homepage": "https://github.com/imanubhardwaj/vue-entity-adapter#readme",
21+
"homepage": "https://github.com/sandrohaiden/vue-entity-adapter-plus#readme",
2222
"devDependencies": {
2323
"@babel/core": "^7.4.0",
2424
"@babel/preset-env": "^7.4.2",

0 commit comments

Comments
 (0)