Skip to content

Commit

Permalink
feat(general): stub out functions so there aren't any ts erros
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Weaver committed Dec 14, 2018
1 parent f168785 commit 503b522
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 22 deletions.
55 changes: 41 additions & 14 deletions src/ropex/RopexIndex.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { EntryKey } from './types';
import { EntryKey, RopexState } from './types';
import { RopexStore } from './RopexStore';

export class RopexIndex<Entry extends object, K extends EntryKey> {
constructor(private readonly ropexStore: RopexStore) {}
constructor(private readonly ropexStore: RopexStore<Entry, K>) {}

// Getters

/**
* Get all the entries in this index
*/
public getAll(): Entry[] {}
public getAll(): Entry[] {
return [];
}

/**
* Return a meta-data field on the index
Expand All @@ -19,7 +21,9 @@ export class RopexIndex<Entry extends object, K extends EntryKey> {
* @param key The meta-data field to look up
* @param defaultVal Default value for the meta-data
*/
public getMetaData<T>(key: string, defaultVal?: T): T {}
public getMetaData<T>(key: string, defaultVal?: T): T {
return defaultVal as T;
}

// Setters

Expand All @@ -32,7 +36,9 @@ export class RopexIndex<Entry extends object, K extends EntryKey> {
* @param entry New entry to set in this index
* @param keyField What field on the object to use as the key
*/
public setEntry(entry: Entry, keyField: string): RopexIndex {}
public setEntry(entry: Entry, keyField: string): RopexIndex<Entry, K> {
return this;
}

/**
* Replace the entries in this index
Expand All @@ -42,7 +48,9 @@ export class RopexIndex<Entry extends object, K extends EntryKey> {
* @param entries New entries to set for this index
* @param keyField What field on the object to use as the key
*/
public setEntries(entries: Entry[], keyField: string): RopexIndex {}
public setEntries(entries: Entry[], keyField: string): RopexIndex<Entry, K> {
return this;
}

/**
* Add a new entry to the index
Expand All @@ -53,7 +61,9 @@ export class RopexIndex<Entry extends object, K extends EntryKey> {
* @param entry New entry to add to the index
* @param keyField What field on the object to use as the key
*/
public addEntry(entry: Entry, keyField: string): RopexIndex {}
public addEntry(entry: Entry, keyField: string): RopexIndex<Entry, K> {
return this;
}

/**
* Add new entries to this index
Expand All @@ -64,30 +74,41 @@ export class RopexIndex<Entry extends object, K extends EntryKey> {
* @param entries New entries to add to this index
* @param keyField What field on the object to use as the key
*/
public addEntries(entries: Entry[], keyField: string): RopexIndex {}
public addEntries(entries: Entry[], keyField: string): RopexIndex<Entry, K> {
return this;
}

/**
* Set a meta-data field
*
* @param key meta-data field key
* @param value what to set the meta-data field as
*/
public setMetaData<T>(key: string, value: T): RopexIndex {}
public setMetaData<T>(key: string, value: T): RopexIndex<Entry, K> {
return this;
}

/**
* Apply a map function to an entry
*
* @param key The key of the entry to apply the map function to
* @param map Function to map an entry to another entry
*/
public mapEntry(key: EntryKey, map: (entry: Entry) => Entry): RopexIndex {}
public mapEntry(
key: EntryKey,
map: (entry: Entry) => Entry,
): RopexIndex<Entry, K> {
return this;
}

/**
* Apply a map function to every entry in the index
*
* @param map Function to map an entry to another entry
*/
public mapEntries(map: (entry: Entry) => Entry): RopexIndex {}
public mapEntries(map: (entry: Entry) => Entry): RopexIndex<Entry, K> {
return this;
}

// Misc

Expand All @@ -96,15 +117,21 @@ export class RopexIndex<Entry extends object, K extends EntryKey> {
*
* @param key The key of the index to lookup
*/
public index(key: K): RopexIndex<Entry, K> {}
public index(key: K): RopexIndex<Entry, K> {
return this;
}

/**
* Complete the current transaction and return the new state
*/
public done(): RopexState {}
public done(): RopexState<Entry, K> {
return this.ropexStore.done();
}

/**
* Remove this index and return the parent {@link RopexStore}
*/
public remove(): RopexStore {}
public remove(): RopexStore<Entry, K> {
return this.ropexStore;
}
}
37 changes: 30 additions & 7 deletions src/ropex/RopexStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@ import { EntryKey, RopexState } from './types';
import { RopexIndex } from './RopexIndex';

export class RopexStore<Entry extends object, K extends EntryKey> {
constructor(private readonly state: RopexState<Entry, K>) {}
private newState: RopexState<Entry, K>;

constructor(readonly state: RopexState<Entry, K>) {
this.newState = JSON.parse(JSON.stringify(state));
}

/**
* Get a ropex index
*
* @param key The key of the index to lookup
*/
public index(key: string): RopexIndex<Entry, K> {}
public index(key: string): RopexIndex<Entry, K> {
return new RopexIndex<Entry, K>(this);
}

/**
* Complete the current transaction and return the new state
*/
public done(): RopexState {}
public done(): RopexState<Entry, K> {
return this.newState;
}

/**
* Replace an entry in this store
Expand All @@ -25,30 +33,45 @@ export class RopexStore<Entry extends object, K extends EntryKey> {
* @param entry New entry to set in this index
* @param keyField What field on the object to use as the key
*/
public setEntry(entry: Entry, keyField: string): RopexStore {}
public setEntry(entry: Entry, keyField: string): RopexStore<Entry, K> {
return this;
}

/**
* Apply a map function to an entry
*
* @param key The key of the entry to apply the map function to
* @param map Function to map an entry to another entry
*/
public mapEntry(key: EntryKey, map: (entry: Entry) => Entry): RopexStore {}
public mapEntry(
key: EntryKey,
map: (entry: Entry) => Entry,
): RopexStore<Entry, K> {
return this;
}

/**
* Apply a map function to every entry in the store
*
* @param map Function to map an entry to another entry
*/
public mapEntries(map: (entry: Entry) => Entry): RopexStore {}
public mapEntries(map: (entry: Entry) => Entry): RopexStore<Entry, K> {
return this;
}

/**
* Run the garbage collector
*/
public gc(): RopexStore<Entry, K> {
return this;
}

/**
* Remove an index from the state
*
* @param index The name of the index to remove
*/
public remove(index: string): RopexStore<Entry, K> {}
public remove(index: string): RopexStore<Entry, K> {
return this;
}
}
4 changes: 3 additions & 1 deletion src/ropex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { RopexStore } from './RopexStore';
*/
export function ropex<E extends object, K extends EntryKey>(
state: RopexState<E, K>,
): RopexStore<E, K> {}
): RopexStore<E, K> {
return new RopexStore<E, K>(state);
}

export namespace ropex {
/**
Expand Down

0 comments on commit 503b522

Please sign in to comment.