Skip to content

Instantly share code, notes, and snippets.

View dfahlander's full-sized avatar

David Fahlander dfahlander

  • Awarica AB
  • Stockholm
View GitHub Profile
// This module shall be imported from BrowserWindow's main modules. The node main thread should instead import "workaround-ipc".
// NOTE: This gist shall not be used if Electron solves issue https://github.com/electron/electron/issues/37417
import Dexie from "dexie";
import { ipcRenderer } from "electron";
if ("unref" in BroadcastChannel.prototype) {
// Node's BroadcastChannel has the `unref()` method.
// Seems we got the Node- and not the DOM version of BroadcastChannel.
// Only activate this workaround when we have the Node-version of BroadcastChannel
@dfahlander
dfahlander / workaround-ipc.ts
Created February 27, 2023 00:02
Electron 23 liveQuery workaround
// This module shall be imported from the main node module in electron.
// The BrowserWindows shall instead import 'workaround-renderer.ts'
// NOTE: This gist shall NOT be used in Electron versions where https://github.com/electron/electron/issues/37417 is resolved
import { ipcMain } from "electron";
import { BrowserWindow } from "electron";
if (typeof BroadcastChannel !== "undefined") {
// We're on electron version 23 with BroadcastChannel support in node
ipcMain.on("dexie-storagemutated", (event, json) => {
@dfahlander
dfahlander / 1.include-dexie-export-import.js
Last active January 6, 2023 11:38
Export-IndexedDB-using-devtools-console
// On any web page that stores things in IndexedDB,
// open devtools and in the console, write the following:
script1 = document.createElement('script');
script1.src = 'https://unpkg.com/dexie@3.2.2';
document.body.appendChild(script1);
script2 = document.createElement('script');
script2.src = 'https://unpkg.com/dexie-export-import@1.0.3';
document.body.appendChild(script2);
@dfahlander
dfahlander / OldFriendsComponent.jsx
Last active January 28, 2021 09:34
Example of a React component using useLiveQuery()
function FriendsComponent({minAge = 75}) {
const friends = useLiveQuery(
() => db.friends
.where('age').aboveOrEqual(minAge)
.toArray()
);
return friends && <ul>{
friends.map(friend =>
<li key={friend.id}>
@dfahlander
dfahlander / observe-old-friends.js
Last active December 13, 2020 15:53
Example of how Dexie's new liveQuery() function works
import Dexie, { liveQuery } from "dexie";
const db = new Dexie('MyDatabase');
db.version(1).stores({
friends: '++id, name, age'
});
const friendsObservable = liveQuery (
() => db.friends
.where('age').above(75)
@dfahlander
dfahlander / index.html
Created September 21, 2016 13:20
Testing Native Promise compatibility with indexedDB
<html>
<script src="https://unpkg.com/dexie/dist/dexie.js"></script>
<script>
const log = txt => console.log(txt);//document.writeln(`${txt}<br/>`);
log (`Hello world!`);
let db = new Dexie ('db');
db.version(1).stores({
friends: '++id,name,age'
});
@dfahlander
dfahlander / index.html
Created September 19, 2016 20:41
Naildown of webkit bug #158833
<html>
<script>
const log = txt => document.writeln(`${txt}<br/>`);
log("Deleting db2");
indexedDB.deleteDatabase("db2").onsuccess = ()=> {
log("db2 deleted");
let req = indexedDB.open("db2", 1);
req.onupgradeneeded = e => {
log ("Creating db2");
let db = req.transaction.db;
@dfahlander
dfahlander / index.html
Last active September 17, 2016 19:29
Test test test
<html>
<script>
document.writeln("Hello world!");
</script>
</html>
@dfahlander
dfahlander / README.md
Last active September 22, 2016 22:33
Repro of IndexedDB bug in Safari10 (webkit bug #158833)

IndexedDB Safari10 bug (webkit bugzilla #158833)

IDBIndex is unreliable on Safari 10

Basically, if you have objectStores 'students' with an index 'name' and 'schools' with an index 'city', and you query the 'name' index on 'students' with no range specified (or WITH a range - it doesnt matter), you will get a cursor that iterates a mix of student names and cities. Each onsuccess callback from the cursor will have a key that sometimes is a student name and sometimes a city. The value though is always a student and some students are shown multiple times - one time with the name key and another time with a city key.

Bugzilla URL

https://bugs.webkit.org/show_bug.cgi?id=158833

@dfahlander
dfahlander / wishlist.md
Last active August 22, 2016 15:41 — forked from nolanlawson/wishlist.md
Safari IndexedDB/WebSQL bug wishlist

Safari IndexedDB/WebSQL bug wishlist

Big overview of what's missing in Safari 7.1+ and iOS 8+ in terms of browser storage.

Updated May 25th 2016

Safari (general)