Skip to content

Commit

Permalink
Merge upstream/master into fix-install
Browse files Browse the repository at this point in the history
  • Loading branch information
saulshanabrook committed Jul 8, 2020
2 parents 6cddbc3 + 70d8c87 commit 7ca423a
Show file tree
Hide file tree
Showing 17 changed files with 1,917 additions and 127 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ yarn-error.log

packages/**/lib
packages/**/build
**/coverage
**/__pycache__
*.profraw
*.tsbuildinfo
.ipynb_checkpoints
*.ipynb
*.ipynb
15 changes: 9 additions & 6 deletions packages/dummystore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@
"devDependencies": {
"@types/chai": "^4.2.8",
"@types/mocha": "^7.0.1",
"chai": "^3.5.0",
"mocha": "^3.2.0",
"karma": "^4.4.1",
"chai": "^4.2.0",
"karma": "^5.0.5",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^1.3.0",
"karma-ie-launcher": "^1.0.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.2",
"rimraf": "^2.5.2",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"karma-typescript": "^4.1.1",
"karma-typescript-es6-transform": "^4.1.1",
"mocha": "^7.1.2",
"rimraf": "^3.0.2",
"typescript": "~3.7.5",
"webpack": "^4.0.0",
"webpack-cli": "^3.3.10"
Expand All @@ -53,6 +55,7 @@
"build": "tsc --build",
"clean": "rimraf lib && rimraf *.tsbuildinfo",
"test": "npm run test:firefox",
"test:debug": "cd tests && karma start --browsers=Chrome --debug=true",
"test:chrome": "cd tests && karma start --browsers=Chrome",
"test:firefox": "cd tests && karma start --browsers=Firefox",
"test:firefox:headless": "cd tests && karma start --browsers=FirefoxHeadless",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ import {

import {
IDatastore
} from './interface';
} from '../interface';

import {
Table
} from './table';


export class Dummystore implements IDatastore, IMessageHandler {
static create(options: IDatastore.IOptions): Dummystore {
static create(options: Dummystore.IOptions): Dummystore {
let {schemas} = options;
// Throws an error for invalid schemas:
Private.validateSchemas(schemas);
Expand All @@ -47,16 +47,25 @@ export class Dummystore implements IDatastore, IMessageHandler {
inTransaction: false,
transactionId: '',
version: 0,
storeId: options.id,
storeId: 0,
change: {},
patch: {},
};

let tables = {} as {[key: string]: Table<Schema>};
// Otherwise, simply create a new, empty table
each(schemas, s => {
tables[s.id] = Table.create(s, context);
});
if (options.restoreState) {
// If passed state to restore, pass the intital state to recreate each
// table
let state = JSON.parse(options.restoreState);
each(schemas, s => {
tables[s.id] = Table.recreate(s, context, state[s.id] || []);
});
} else {
// Otherwise, simply create a new, empty table
each(schemas, s => {
tables[s.id] = Table.create(s, context);
});
}

return new Dummystore(context, tables);
}
Expand Down Expand Up @@ -91,9 +100,6 @@ export class Dummystore implements IDatastore, IMessageHandler {
*
* The payload represents the set of local changes that were made
* to bring the store to its current state.
*
* #### Complexity
* `O(1)`
*/
get changed(): ISignal<IDatastore, Datastore.IChangedArgs> {
return this._changed;
Expand All @@ -104,19 +110,13 @@ export class Dummystore implements IDatastore, IMessageHandler {
*
* #### Notes
* The id is unique among all other collaborating peers.
*
* #### Complexity
* `O(1)`
*/
get id(): number {
return this._context.storeId;
}

/**
* Whether a transaction is currently in progress.
*
* #### Complexity
* `O(1)`
*/
get inTransaction(): boolean {
return this._context.inTransaction;
Expand All @@ -129,9 +129,6 @@ export class Dummystore implements IDatastore, IMessageHandler {
* This version is automatically increased for each transaction
* to the store. However, it might not increase linearly (i.e.
* it might make jumps).
*
* #### Complexity
* `O(1)`
*/
get version(): number {
return this._context.version;
Expand All @@ -154,9 +151,6 @@ export class Dummystore implements IDatastore, IMessageHandler {
* @returns The table for the specified schema.
*
* @throws An exception if no table exists for the given schema.
*
* #### Complexity
* `O(log32 n)`
*/
get<S extends Schema>(schema: S): Table<S> {
let t = this._tables[schema.id];
Expand Down Expand Up @@ -332,6 +326,21 @@ export class Dummystore implements IDatastore, IMessageHandler {
}


export namespace Dummystore {
export interface IOptions {
/**
* The table schemas of the datastore.
*/
schemas: ReadonlyArray<Schema>;

/**
* Initialize the state to a previously serialized one.
*/
restoreState?: string;
}
}


namespace Private {
/**
* Validates all schemas, and throws an error if any are invalid.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import './dummystore.spec';
export * from './datastore';
export * from './table';
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {

import {
ITable
} from './interface';
} from '../interface';


/**
Expand All @@ -40,10 +40,22 @@ export class Table<S extends Schema> implements ITable<S> {
}

/**
* The schema for the table.
* @internal
*
* Create a new datastore table with a previously exported state.
*
* @param schema - The schema for the table.
*
* @param context - The datastore context.
*
* #### Complexity
* `O(1)`
* @returns A new datastore table.
*/
static recreate<U extends Schema>(schema: U, context: Datastore.Context, records: IterableOrArrayLike<Record<U>>): Table<U> {
return new Table<U>(schema, context, records);
}

/**
* The schema for the table.
*/
readonly schema: S;

Expand All @@ -65,9 +77,6 @@ export class Table<S extends Schema> implements ITable<S> {
* Create an iterator over the records in the table.
*
* @returns A new iterator over the table records.
*
* #### Complexity
* `O(log32 n)`
*/
iter(): IIterator<Record<S>> {
return map(Object.keys(this._records), key => this._records[key]);
Expand Down Expand Up @@ -264,6 +273,7 @@ namespace Private {
// Compute the new value.
value = value.slice(0, index) + text + value.slice(index + count);
}
break;
case 'list':
// Create a clone of the previous value.
let listClone = [...previous[name] as any[]];
Expand Down Expand Up @@ -335,7 +345,7 @@ namespace Private {
break;
case 'register':
value = update[name]!;
change = {previous, current: value};
change = {previous: previous[name], current: value};
break;
default:
throw new Error(`Dummystore cannot handle field type: ${field.type}`);
Expand Down

0 comments on commit 7ca423a

Please sign in to comment.