Skip to content

Commit

Permalink
add change listener in main
Browse files Browse the repository at this point in the history
  • Loading branch information
yadPe committed Aug 14, 2022
1 parent 5dcb9eb commit 9e03d7a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ const go = () => {
};

const realm = new Realm(configg);

const dogs = realm.objects('Dog');
console.log(`Renderer: Number of Dog objects: ${dogs.length}`);

realm.write(() => {
realm.create('Dog', {
_id: 1,
name: 'Spot',
age: 2,
});
});
};

const App = () => {
Expand Down
32 changes: 28 additions & 4 deletions src/electron/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ log.transports.file.level = 'debug';
autoUpdater.logger = log;
log.catchErrors();

const installExtensions = async extensions => {
return Promise.all(
const installExtensions = async extensions =>
Promise.all(
extensions.map(extension =>
extensionInstaller(extension)
.then(name => console.log(`[extensionInstaller]: Installed ${name}!`))
.catch(err => console.log('[extensionInstaller]: An error occurred: ', err)),
),
);
};

const CUSTOM_PROTOCOL = 'beatconnect';

Expand Down Expand Up @@ -61,9 +60,34 @@ const main = async () => {
path: 'my.realm',
};

// open a synced realm
const realm = await Realm.open(config);

realm.write(() => {
realm.deleteAll();
});

realm.write(() => {
realm.create('Dog', {
_id: 2,
name: 'Fido',
age: 5,
});
});

const dogs = realm.objects('Dog');
console.log(`Main: Number of Dog objects: ${dogs.length}`);

dogs.addListener((dogs, changes) => {
changes.insertions.forEach(index => {
const insertedDog = dogs[index];
console.log(`Main: Inserted ${insertedDog.name}`);
});

changes.deletions.forEach(index => {
console.log(`Main: Dog ${index} deleted`);
});
});

mainWindow = makeMainWindow({
content: join(__dirname, 'index.html'),
});
Expand Down

0 comments on commit 9e03d7a

Please sign in to comment.