profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/alecgibson/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.

alecgibson/DefinitelyTyped 0

The repository for high quality TypeScript type definitions.

alecgibson/ejs 0

Embedded JavaScript templates -- http://ejs.co

alecgibson/electron-quick-start 0

Clone to try a simple Electron app

alecgibson/epub-gen 0

Generate EPUB books from HTML with simple API in Node.js.

delete branch alecgibson/DefinitelyTyped

delete branch : sharedb-fixes

delete time in 5 hours

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentDefinitelyTyped/DefinitelyTyped

sharedb: add missing argument to `op` and `before op` events

 export interface DocEventMap<T> {     'no write pending': () => void;     'nothing pending': () => void;     'create': (source: any) => void;-    'op': (ops: [any], source: any) => void;+    'op': (ops: [any], source: any, clientId: any) => void;     'op batch': (ops: any[], source: any) => void;-    'before op': (ops: [any], source: any) => void;+    'before op': (ops: [any], source: any, clientId: any) => void;
    'before op': (ops: [any], source: any, clientId: string) => void;
victorborrasdev

comment created time in 5 hours

Pull request review commentDefinitelyTyped/DefinitelyTyped

sharedb: add missing argument to `op` and `before op` events

 export interface DocEventMap<T> {     'no write pending': () => void;     'nothing pending': () => void;     'create': (source: any) => void;-    'op': (ops: [any], source: any) => void;+    'op': (ops: [any], source: any, clientId: any) => void;
    'op': (ops: [any], source: any, clientId: string) => void;

We should match the (upcoming) update to Connection

victorborrasdev

comment created time in 5 hours

PullRequestReviewEvent

PR opened share/sharedb

✅ Try to fix flaky query subscribe test

This is a speculative fix for https://github.com/share/sharedb/issues/502

It seems impossible to get this test to fail locally, so this change makes some generic quality-of-life improvements on the test code in the hopes that we improve its stability:

  • wait for the insert and removes to be acked on connection2 before reconnection connection
  • catch del() errors
  • change the query listeners to .once() to avoid multiple calls
+17 -8

0 comment

1 changed file

pr created time in 6 hours

create barnchshare/sharedb

branch : flaky-subscribe-test

created branch time in 6 hours

PR opened share/sharedb

✅ Fix flaky test

Fixes https://github.com/share/sharedb/issues/503

This change fixes a flaky test, which relies on a setTimeout with a 10ms wait.

This change replaces the use of a setTimeout with an event listener, which is not prone to flakiness, and is more semantic.

+8 -9

0 comment

1 changed file

pr created time in 7 hours

create barnchshare/sharedb

branch : flaky-projection-test

created branch time in 7 hours

push eventalecgibson/DefinitelyTyped

Alec Gibson

commit sha 7741cba96d86915c5fa22fed4ac985cd9f5ffc20

sharedb: add `Connection` properties The type definition for the `Connection` class is currently missing most of its [instance properties][1]. This change adds the non-prefixed properties to the type definitions. [1]: https://github.com/share/sharedb/blob/5c9148dc44d2c43582386875ed76c08070cfce3f/lib/client/connection.js#L39-L73

view details

push time in 7 hours

Pull request review commentDefinitelyTyped/DefinitelyTyped

sharedb: add `Connection` properties

 export class Connection {     // ShareDB, but it is handy for server-side only user code that may cache     // state on the agent and read it in middleware     agent: Agent | null;++    collections: Record<string, Record<string, Doc>>;+    queries: Record<string, Query>;++    seq: number;+    id: string;

(I personally find | null to be noise in TS, because every property can be set to null, so it doesn't really add anything, but fine)

alecgibson

comment created time in 7 hours

PullRequestReviewEvent

delete branch reedsy/vue-test-utils

delete branch : generic-element-fix

delete time in a day

PR opened DefinitelyTyped/DefinitelyTyped

sharedb: add `Connection` properties

The type definition for the Connection class is currently missing most of its instance properties. This change adds the non-prefixed properties to the type definitions.

Please fill in this template.

If changing an existing definition:

  • [x] Provide a URL to documentation or source code which provides context for the suggested changes: <<url here>>
  • [x] If this PR brings the type definitions up to date with a new version of the JS library, update the version number in the header.
+14 -0

0 comment

2 changed files

pr created time in a day

create barnchalecgibson/DefinitelyTyped

branch : sharedb

created branch time in a day

PullRequestReviewEvent

delete branch reedsy/json0

delete branch : remove-tests

delete time in a day

Pull request review commentshare/sharedb-mongo

Pass isForSubmit = true to BeforeSnapshotLookup Middleware When Lookup is For Op Submit

 ShareDbMongo.prototype.commit = function(collectionName, id, op, snapshot, optio     self._writeSnapshot(request, id, snapshot, opId, function(err, succeeded) {       if (succeeded) return callback(err, succeeded);       // Cleanup unsuccessful op if snapshot write failed. This is not-      // neccessary for data correctness, but it gets rid of clutter+      // necessary for data correctness, but it gets rid of clutter       self._deleteOp(request.collectionName, opId, function(removeErr) {         callback(err || removeErr, succeeded);       });     });   }); }; -function createRequestForMiddleware(options, collectionName, op) {+function createRequestForMiddleware(options, collectionName, op, fields) {+  // When we're creating a request for submitting an op, let downstream middleware know.+  if (fields && fields.$submit === true) {+    if (!options) {+      options = {};+    }+    /**+     * TODO What if sharedb populated this?

(On this, in future I think we should potentially provide the corresponding ShareDB lifecycle hook, but definitely out-of-scope for this change)

dwinrick-lever

comment created time in 2 days

Pull request review commentshare/sharedb-mongo

Pass isForSubmit = true to BeforeSnapshotLookup Middleware When Lookup is For Op Submit

 ShareDbMongo.prototype.commit = function(collectionName, id, op, snapshot, optio     self._writeSnapshot(request, id, snapshot, opId, function(err, succeeded) {       if (succeeded) return callback(err, succeeded);       // Cleanup unsuccessful op if snapshot write failed. This is not-      // neccessary for data correctness, but it gets rid of clutter+      // necessary for data correctness, but it gets rid of clutter       self._deleteOp(request.collectionName, opId, function(removeErr) {         callback(err || removeErr, succeeded);       });     });   }); }; -function createRequestForMiddleware(options, collectionName, op) {+function createRequestForMiddleware(options, collectionName, op, fields) {+  // When we're creating a request for submitting an op, let downstream middleware know.+  if (fields && fields.$submit === true) {+    if (!options) {+      options = {};+    }+    /**+     * TODO What if sharedb populated this?+     *  It looks like we would have the following values for 'trigger': submitRequest, queryEmit, fetch+     */+    options.triggeredBy = 'submitRequest';

I'm not really sure this should live on options — isn't that the object ShareDB called the driver with?

I think it probably makes more sense for triggeredBy to just be an (optional) top-level property in request.

dwinrick-lever

comment created time in 2 days

PullRequestReviewEvent
PullRequestReviewEvent

pull request commentvuejs/vue-test-utils

fix: revert default element typings to `HTMLElement`

Why is this an anti pattern?

I think it's an anti-pattern, because a purist would argue that this use of generics offers no "real" type safety. For example, a classic example of a generic might be the Array:

const arr = new Array<number>();
arr.push(1);
const item: number = arr.pop();

The generic here offers type-safety, because it ties everything about the class together: you definitely can only add a number, and always are guaranteed to get a number.

If the Array (hypothetically) let you override its generic types on its instance methods, you could write something like:

const arr = new Array(); // Defaults to any
arr.push<number>(1);
const item = arr.pop<string>();

...then you've not gained anything from the type system, and you're just abusing the fact that the methods let you override the expected type — essentially you've just cast the result — which then begs the question of what value is the type system adding here.

If we follow our wrapper.find<HTMLElement>() {} to its logical extreme, it's akin to writing:

function foo<T extends any = any>(): T {}
const bar = foo<string>();

...which really offers no more type safety than this:

function foo(): any {}
const bar = foo() as string;

Using as XXX allows you to write any type, which might not be valid

That is not the case:

Screen Shot 2021-07-28 at 08 38 47

However, all that being said, as a pragmatist, I do think if we're going to be forced to constantly cast our find() results, then this syntax:

wrapper.find<HTMLElement>('.foo').element.click()

is arguably "nicer" than this syntax:

(wrapper.find('.foo').element as HTMLElement).click()
// Or alternatively...
(<HTMLElement> wrapper.find('.foo').element).click()
alecgibson

comment created time in 2 days

PullRequestReviewEvent

Pull request review commentshare/sharedb-mongo

Pass isForSubmit = true to BeforeSnapshotLookup Middleware When Lookup is For Op Submit

 ShareDbMongo.prototype.getSnapshot = function(collectionName, id, fields, option     if (err) return callback(err);     var query = {_id: id};     var projection = getProjection(fields, options);-    var request = createRequestForMiddleware(options, collectionName);+    var request = createRequestForMiddleware(fields, options, collectionName);     request.query = query;     self._middleware.trigger(MiddlewareHandler.Actions.beforeSnapshotLookup, request, function(middlewareErr) {       if (middlewareErr) return callback(middlewareErr); -      collection.find(request.query).limit(1).project(projection).next(function(err, doc) {+      collection.find(request.query, request.queryOptions).limit(1).project(projection).next(function(err, doc) {

Then shouldn't we be passing these options everywhere we call find()?

dwinrick-lever

comment created time in 3 days

pull request commentDefinitelyTyped/DefinitelyTyped

sharedb: various fixes

Ready to merge

alecgibson

comment created time in 3 days

Pull request review commentDefinitelyTyped/DefinitelyTyped

sharedb: various fixes

 interface SubmitRequest {     channels: string[] | null; } +interface GetOpsOptions {+    opsOptions?: {+        metadata?: boolean;

I think it's weird to force true in the type definition. It's perfectly valid to write code that programmatically requests metadata:

const options = {
  opsOptions: {
    metadata: shouldFetchMetadata(),
  },
};

function shouldFetchMetadata(): boolean {
  // Do complex logic to determine if we want to fetch metadata
}
alecgibson

comment created time in 3 days

PullRequestReviewEvent

pull request commentvuejs/vue-test-utils

fix: revert default element typings to `HTMLElement`

As a side-note, it sounds like using this sort of generic typing where the type isn't used in the parameter list is an anti-pattern, and I guess now I think about it, I don't really understand the value of doing this over just forcing consumers to cast:

const button = wrapper.find('.button') as HTMLButtonElement;
alecgibson

comment created time in 3 days

pull request commentvuejs/vue-test-utils

fix: revert default element typings to `HTMLElement`

Yes it's fine if you reference by element tag, but I personally tend to avoid that to keep tests from being too fragile (and often looking things up by just eg div are usually not specific enough).

The scope of this PR was just to make the change un-breaking; so if you want to adopt the v3 types, that should probably be a different change.

alecgibson

comment created time in 3 days