Skip to content

Commit

Permalink
Merge branch 'MonsieurMan-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Netanel Basal committed Jul 17, 2018
2 parents 8dcf8ef + 1da3ae0 commit fbe0ffc
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 27 deletions.
9 changes: 9 additions & 0 deletions akita/src/api/arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { isObject } from '../internal/utils';
* Adds one or more elements to the end of an array by returning
* a new array instead of mutating the original one.
*
* @example
* const originalArray = ['a', 'b', 'c', 'd', 'e'];
* const resultArray = push(originalArray, 'f', 'g');
* // -> originalArray ['a', 'b', 'c', 'd', 'e']
Expand All @@ -18,6 +19,7 @@ export function push<T>(array: T[], ...elementN): T[] {
/**
* Deletes an element from an array by its index in the array.
*
* @example
* const originalArray = ['a', 'b', 'c', 'd', 'e'];
* const resultArray = remove(originalArray, 2);
* // -> originalArray ['a', 'b', 'c', 'd', 'e']
Expand All @@ -31,6 +33,7 @@ export function remove<T>(array: T[], index: number): T[] {
* Removes the last element from an array by returning
* a new array instead of mutating the original one.
*
* @example
* const originalArray = ['a', 'b', 'c', 'd', 'e'];
* const resultArray = pop(originalArray);
* // -> originalArray ['a', 'b', 'c', 'd', 'e']
Expand All @@ -43,6 +46,7 @@ export function pop<T>(array: T[]): T[] {
/**
* Adds one or more elements to the beginning of an array.
*
* @example
* const originalArray = ['a', 'b', 'c', 'd', 'e'];
* const resultArray = unshift(originalArray, 'f', 'g');
* // -> originalArray ['a', 'b', 'c', 'd', 'e']
Expand All @@ -55,6 +59,7 @@ export function unshift<T>(array: T[], ...elementN): T[] {
/**
* Sorts the elements of an array (not in place) and returns a sorted array.
*
* @example
* const numberArray = [20, 3, 4, 10, -3, 1, 0, 5];
* const stringArray = ['Blue', 'Humpback', 'Beluga'];
*
Expand Down Expand Up @@ -82,6 +87,7 @@ export function sort<T>(array: T[], compareFunction?: (a: T, b: T) => number): T
* Reverses an array (not in place).
* The first array element becomes the last, and the last array element becomes the first.
*
* @example
* const originalArray = ['a', 'b', 'c', 'd', 'e'];
* const resultArray = reverse(originalArray);
* // -> originalArray ['a', 'b', 'c', 'd', 'e']
Expand All @@ -94,6 +100,7 @@ export function reverse<T>(array: T[]): T[] {
/**
* Swap items in the array
*
* @example
* const originalArray = ['a', 'b', 'c', 'd', 'e'];
* const resultArray = swap(originalArray, 1, 4);
* // -> originalArray ['a', 'b', 'c', 'd', 'e']
Expand All @@ -111,6 +118,7 @@ export function swap<T>(array: T[], firstIndex: number, secondIndex: number): T[
/**
* Update item in the array
*
* @example
* const originalArray = ['a', 'b', 'c', 'd', 'e'];
* const resultArray = update(originalArray, 1, 'newItem');
* // -> resultArray ['a', 'newItem', 'c', 'd', 'b']
Expand Down Expand Up @@ -139,6 +147,7 @@ export function update<T>(array: T[], indexOrItem: number | object, updated: any
/**
* Removes existing elements and/or adds new elements to an array.
*
* @example
* const originalArray = ['a', 'b', 'c', 'd', 'e'];
* const resultArray = splice(originalArray, 0);
* // -> originalArray ['a', 'b', 'c', 'd', 'e']
Expand Down
7 changes: 7 additions & 0 deletions akita/src/api/entity-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class EntityStore<S extends EntityState<E>, E> extends Store<S> {
*
* Replace current collection with provided collection
*
* @example
* this.store.set([Entity, Entity]);
* this.store.set({1: Entity, 2: Entity});
* this.store.set([{id: 1}, {id: 2}], Product);
Expand All @@ -73,6 +74,7 @@ export class EntityStore<S extends EntityState<E>, E> extends Store<S> {
/**
* Create or replace an entity in the store.
*
* @example
* this.store.createOrReplace(3, Entity);
*
*/
Expand All @@ -90,6 +92,7 @@ export class EntityStore<S extends EntityState<E>, E> extends Store<S> {
/**
* Add an entity or entities to the store.
*
* @example
* this.store.add([Entity, Entity]);
* this.store.add(Entity);
*/
Expand All @@ -104,6 +107,7 @@ export class EntityStore<S extends EntityState<E>, E> extends Store<S> {
*
* Update an entity or entities in the store.
*
* @example
* this.store.update(3, {
* name: 'New Name'
* });
Expand Down Expand Up @@ -150,6 +154,7 @@ export class EntityStore<S extends EntityState<E>, E> extends Store<S> {
/**
* Update the root state (data which is external to the entities).
*
* @example
* this.store.updateRoot({
* metadata: 'new metadata
* });
Expand Down Expand Up @@ -184,6 +189,7 @@ export class EntityStore<S extends EntityState<E>, E> extends Store<S> {
*
* Remove one or more entities from the store:
*
* @example
* this.store.remove(5);
* this.store.remove([1,2,3]);
* this.store.remove();
Expand All @@ -202,6 +208,7 @@ export class EntityStore<S extends EntityState<E>, E> extends Store<S> {
*
* Update the active entity.
*
* @example
* this.store.updateActive(active => {
* return {
* config: {
Expand Down
5 changes: 5 additions & 0 deletions akita/src/api/query-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class QueryEntity<S extends EntityState, E> extends Query<S> {
/**
* Select the entire store's entity collection.
*
* @example
* this.store.selectAll();
*/
selectAll(options: { asObject: true; filterBy?: SelectOptions<E>['filterBy']; limitTo?: number; sortBy?: undefined; sortByOrder?: undefined }): Observable<HashMap<E>>;
Expand Down Expand Up @@ -72,6 +73,7 @@ export class QueryEntity<S extends EntityState, E> extends Query<S> {
/**
* Get the entire store's entity collection.
*
* @example
* this.store.getAll();
*/
getAll(options: { asObject: true; filterBy?: SelectOptions<E>['filterBy']; limitTo?: number }): HashMap<E>;
Expand All @@ -94,6 +96,7 @@ export class QueryEntity<S extends EntityState, E> extends Query<S> {
/**
* Select multiple entities from the store.
*
* @example
* this.store.selectMany([1,2]);
*/
selectMany(ids: ID[], options: { asObject: true }): Observable<HashMap<E>>;
Expand Down Expand Up @@ -129,6 +132,7 @@ export class QueryEntity<S extends EntityState, E> extends Query<S> {
/**
* Select an entity or a slice of an entity.
*
* @example
* this.pagesStore.selectEntity(1)
* this.pagesStore.selectEntity(1, entity => entity.config.date)
*
Expand All @@ -152,6 +156,7 @@ export class QueryEntity<S extends EntityState, E> extends Query<S> {
/**
* Get an entity by id
*
* @example
* this.store.getEntity(1);
*/
getEntity(id: ID): E {
Expand Down
1 change: 1 addition & 0 deletions akita/src/api/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class Query<S> {
/**
* Select a slice from the store.
*
* @example
* this.query.select(state => state.entities)
*/
select<R>(project: (store: S) => R): Observable<R> {
Expand Down
2 changes: 2 additions & 0 deletions akita/src/api/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class Store<S> {
/**
* Select a slice from the store
*
* @example
* this.store.select(state => state.entities)
*
*/
Expand Down Expand Up @@ -116,6 +117,7 @@ export class Store<S> {
* This method is a shortcut for `setState()`.
* It can be useful when you want to pass the whole state object instead of merging a partial state.
*
* @example
* this.store.update(newState)
*/
update(newState: Partial<S>);
Expand Down
2 changes: 2 additions & 0 deletions akita/src/api/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { endBatch, startBatch } from '../internal/transaction.internal';
* Use this transaction to optimize the dispatch of all the stores.
* The following code will update the store, BUT emits only once
*
* @example
* applyTransaction(() => {
* this.todosStore.add(new Todo(1, title));
* this.todosStore.add(new Todo(2, title));
Expand All @@ -26,6 +27,7 @@ export function applyTransaction<T>(action: () => T, thisArg = undefined): T {
*
* The following code will update the store, BUT emits only once.
*
* @example
* @transaction
* addTodos() {
* this.todosStore.add(new Todo(1, title));
Expand Down
1 change: 1 addition & 0 deletions akita/src/api/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* An interface to represent objects
*
* @example
* const dashboards: HashMap<Dashboard> = {
* 1: Dashboard
* }
Expand Down
1 change: 1 addition & 0 deletions akita/src/api/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function createWorker() {
}

/**
* @example
* const mockTodos = Array.from({length: 10000}, (_, x) => ({id: x}));
*
* of(mockTodos).pipe(mapInWorker<Todo>(createTodo))
Expand Down
Loading

0 comments on commit fbe0ffc

Please sign in to comment.