Skip to content

Commit

Permalink
Ajout StoreListNode.pushNode(item)
Browse files Browse the repository at this point in the history
  • Loading branch information
JabX committed Nov 29, 2017
1 parent deabebb commit 9402bc2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "focus4",
"version": "8.3.4",
"version": "8.3.5",
"description": "Focus v4 (Typescript + MobX)",
"main": "index.js",
"repository": {
Expand All @@ -25,7 +25,7 @@
"@types/core-decorators": "0.10.32",
"@types/glob": "5.0.33",
"@types/i18next": "8.4.2",
"@types/lodash": "4.14.82",
"@types/lodash": "4.14.86",
"@types/numeral": "0.0.22",
"@types/prop-types": "15.5.2",
"@types/react": "15.0.1",
Expand All @@ -37,16 +37,16 @@
"@types/tape": "4.2.31",
"@types/uuid": "3.4.3",
"core-decorators": "0.20.0",
"i18next": "10.0.7",
"i18next": "10.2.1",
"ignore-styles": "5.0.1",
"inversify": "4.5.1",
"inversify": "4.5.2",
"inversify-inject-decorators": "3.0.2",
"lodash": "4.17.4",
"lodash-decorators": "4.5.0",
"material-design-icons-iconfont": "3.0.3",
"mobx": "3.3.1",
"mobx-react": "4.3.4",
"moment": "2.19.1",
"mobx": "3.3.2",
"mobx-react": "4.3.5",
"moment": "2.19.3",
"numeral": "2.0.6",
"react": "15.6.2",
"react-addons-test-utils": "15.6.2",
Expand All @@ -64,14 +64,14 @@
"yester": "0.10.0"
},
"devDependencies": {
"@types/shelljs": "0.7.5",
"@types/shelljs": "0.7.6",
"in-publish": "2.0.0",
"shelljs": "0.7.8",
"stylelint": "8.2.0",
"stylelint": "8.3.1",
"tap-spec": "4.1.1",
"ts-node": "3.3.0",
"tslint": "5.8.0",
"typed-css-modules": "0.3.1",
"typescript": "2.6.1"
"typescript": "2.6.2"
}
}
12 changes: 12 additions & 0 deletions src/entity/__test__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ test("EntityStore: Clear global", t => {
t.end();
});

test("EntityStore: Ajout élément dans une liste", t => {
const store = getStore();

store.structureList.set(structureList);
store.structureList.pushNode({id: 8});
t.assert(store.structureList.length === 4, "La liste 'structureList' possède bien un élément de plus.");
t.deepEqual(store.structureList[3].id.$entity, StructureEntity.fields.id, "L'élément ajouté est bien un node avec les bonnes métadonnées.");
t.equal(store.structureList[3].id.value, 8, "L'élement ajouté possède bien les valeurs attendues");

t.end();
})

test("EntityStore: Clear locaux", t => {
const store = getStore();

Expand Down
11 changes: 11 additions & 0 deletions src/entity/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { Entity, EntityField, FieldEntry, ListEntry, ObjectEntry } from "./types

/** Fonction `set`. */
export interface Setter<T> {
/** Renseigne les valeurs du noeud à partir des champs fournis. */
set(config: Partial<T>): void;
}

/** Fonction `clear`. */
export interface Clearer {
/** Vide l'objet (récursivement). */
clear(): void;
}

Expand All @@ -26,7 +28,11 @@ export interface StoreNode<T = {}> extends Setter<T>, Clearer {}
* `T` doit être un `StoreNode` et `StoreListNode` est également considéré comme un `StoreNode`.
*/
export interface StoreListNode<T extends StoreNode = StoreNode> extends IObservableArray<T> {
/** Métadonnées. */
$entity: Entity;
/** Ajoute un élément à la liste. */
pushNode(item: {}): void;
/** Reconstruit la liste à partir des données fournies. */
set(array: {}[]): void;
}

Expand Down Expand Up @@ -133,6 +139,11 @@ export function buildEntityEntry<T extends EntityStoreConfig>(config: EntityStor
if (isArray(entity)) {
const outputEntry: StoreListNode<EntityStoreNode> = observable([]) as any;
outputEntry.$entity = entityMap[trueEntry];
outputEntry.pushNode = action(function pushNode(this: typeof outputEntry, item: {}) {
const itemNode = buildEntityEntry({[trueEntry]: {}} as EntityStoreConfig, {...entityMap, item: entity.$entity}, entityMapping, trueEntry) as EntityStoreNode;
itemNode.set(item);
this.push(itemNode);
});
outputEntry.set = action(function set(this: typeof outputEntry, values: {}[]) { setEntityEntry(this, entityMap, entityMapping, values, trueEntry); });
return outputEntry;
}
Expand Down
3 changes: 3 additions & 0 deletions src/entity/view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ function clone(source: any): any {
if ((source as any).$entity) {
(res as any).$entity = (source as any).$entity;
}
if ((source as any).pushNode) {
(res as any).pushNode = (source as any).pushNode;
}
if ((source as any).set) {
(res as any).set = (source as any).set;
}
Expand Down

0 comments on commit 9402bc2

Please sign in to comment.