IPC

IPCRecord object

Property
Type
Description

id

number

randomly generated id of record

time

number

timestamp (in ms) when this record was made

data

any

content of this record

record.pop()

Remove record from the storage

import { IPC } from '@empathize/framework';

IPC.read().then((records) => {
    records.forEach((record) => {
        if (record.data == 'test-data')
            record.pop(); // Otherwise this record will remain in IPC.read() output
    });
});

record.get()

Get object of record values

import { IPC } from '@empathize/framework';

IPC.read().then((records) => {
    records.forEach((record) => {
        if (record.data == 'test-data')
        {
            // record.pop() method returns this record after its deletion
            // and we can call its .get() method after that
            const recordData = record.pop().get();
            
            // It will output { id: '...', time: '...', data: '...' }
            console.log(recordData);
        }
    });
});

IPC class

IPC.file

File where ipc records should be stored

IPC.read()

Get IPC records

import { IPC } from '@empathize/framework';

IPC.read().then((records) => {
    for (const record of records)
        console.log(record.data);
});

IPC.write(data)

Create record

import { IPC } from '@empathize/framework';

// It can be string, ..
IPC.write('test-record');

// ..object or something else
IPC.write({
    example_field: 'example_value'
});

IPC.remove(record)

Remove record

import { IPC } from '@empathize/framework';

IPC.write('test-record').then((record) => {
    // Remove this record after 3 seconds
    setTimeout(() => {
        // Can be IPCRecord object or record id
        IPC.remove(record);
    }, 3000);
});

IPC.purge()

Remove all records

import { IPC, promisify } from '@empathize/framework';

promisify(async () => {
    // Add 10 records
    for (let i = 0; i < 10; ++i)
        await IPC.write('test');
    
    // Records amount: 10
    console.log(`Records amount: ${(await IPC.read()).length}`);
    
    // Remove all records
    await IPC.purge();
    
    // Records amount: 0
    console.log(`Records amount: ${(await IPC.read()).length}`);
});

Last updated