This is the MemStore implementaion as used in Replicache 12.1
This depends on files not included in this gist but these should be pretty self describing.
| import type {Immutable} from './immutable.js'; | |
| type Todo = { | |
| id: string; | |
| done: boolean; | |
| order: string; | |
| text: string; | |
| }; | |
| type ImmutableTodo = Immutable<Todo>; |
node --version # v17.9.0
npm --version # 8.5.5
npm install
npm run test| import { useEffect, useState } from "react"; | |
| import { MutatorDefs, Replicache, ReplicacheOptions } from "replicache"; | |
| export function useReplicache<MD extends MutatorDefs>( | |
| opts: ReplicacheOptions<MD> | |
| ): Replicache<MD> | null { | |
| const [rep, setRep] = useState<Replicache<MD> | null>(null); | |
| useEffect(() => { | |
| const r = new Replicache(opts); | |
| setRep(r); |
| 'use strict'; | |
| class Base { | |
| constructor(x) { | |
| this.x = x; | |
| } | |
| } | |
| let f; | |
| class D1 extends Base { | |
| constructor() { |
| createPropertyAccessor: function(name, ignoreWrites) { | |
| var proto = this.prototype; | |
| var privateName = name + '_'; | |
| var privateObservable = name + 'Observable_'; | |
| Object.defineProperty(proto, name, { | |
| get: function() { | |
| var observable = this[privateObservable]; | |
| if (observable) | |
| observable.deliver(); |
| var assert = { | |
| equal: function(x, y) { | |
| if (x === y) return; | |
| throw new Error(); | |
| }, | |
| isTrue: function(x) { | |
| if (x) return; | |
| throw new Error(); | |
| } | |
| }; |
At the July TC39 meeting we decided to explore removing @@create in favor of a model where super() in a [[Construct]] call creates the instance object. To correctly know how to create the instance and set the prototype a [[Construct]] call gets an implicit receiver which is the constructor function new was called with.
class Base {
constructor() {
var object = Object.create(new*.prototype); // new binding needs new syntax...
// bikeshed...
myWeakMap.set(object, myHiddenData);
return object;
}| // Use Gists to store code you would like to remember later on | |
| console.log(window); // log the "window" object to the console |
WithStatement : with ( Expression ) Statement