-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Racer 2 #302
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial comments on several files, still a bunch more to go through
// (value, null) | ||
value = arguments[0]; | ||
cb = arguments[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there cases where null
is passed as a callback explicitly?
src/Model/mutators.ts
Outdated
@@ -167,7 +333,7 @@ Model.prototype._create = function(segments, value, cb) { | |||
var event = new ChangeEvent(value, previous, model._pass); | |||
model._emitMutation(segments, event); | |||
} | |||
this._mutate(segments, create, cb); | |||
return this._mutate(segments, create, cb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The typing of model.create()
indicates that it doesn't return anything (void return), so a technically more accurate thing to do would be:
- Remove the return above in
return this._create(segments, value, cb);
- Then this new extra
return
here isn't needed - Same in
_createNull
, the new return is no longer needed either
src/Model/mutators.ts
Outdated
pushPromised(value: any): Promise<number>; | ||
pushPromised(subpath: Path, value: any): Promise<number>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think so, since callback doesn't get invoked with any result
src/Model/Doc.ts
Outdated
import { Collection } from './collections'; | ||
import { Path } from '../types'; | ||
|
||
function Doc(model, collectionName, id) { | ||
this.collectionName = collectionName; | ||
this.id = id; | ||
this.collectionData = model && model.data[collectionName]; | ||
} | ||
export class Doc { | ||
collectionData: Model; | ||
collectionName: string; | ||
data: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data
only appears to be used by LocalDoc, not RemoteDoc. Might be possible to move it to the LocalDoc subclass, instead of having it here in the base class
if (segments && segments.length) path += '.' + segments.join('.'); | ||
return path; | ||
}; | ||
constructor(model: Model, collectionName: string, id: string, data?: any, _collection?: Collection) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can probably remove the final unused _collection
param
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used here https://github.com/derbyjs/racer/blob/racer-2/src/Model/collections.ts#L211
But cant see why this is passed 🤷
... oh.. used on RemoteDoc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing it leads to type errors where we pass it, then removing that leads to test errors. Looks like a rabbit hole for later
} | ||
|
||
export class RootModel extends Model<ModelData> { | ||
backend: RacerBackend; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically should be optional, as it's only present on server-side models created with backend.createModel()
, but may cause type breakages if made optional. Could try it and see
src/index.ts
Outdated
export function createBackend(options?: BackendOptions) { | ||
return new RacerBackend(racer, options); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, it might cause a bundler to bring in the backend code. We could change this to a stub implementation that throws, and switch the RacerBackend to a type import for type info
…ay cases that don't actually occur
racer@2 breaking changes:
Model
class should no longer be directly constructed. UsecreateModel()
instead.new racer.Model()
->racer.createModel()
Model
can result in errors likeCannot set properties of undefined (setting 'socket')
fromModel.createConnection
racer
no longer and instance.racer
now a proper namespacegetModel()
method formreq
object inmodelMiddleware