@sagarjain0907/firepad
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Usage

Public API

Firepad takes two dependencies, one Database Adapter and one Editor Adapter, with a custom configuration object like the following:

import Firepad, { IDatabaseAdapter, IEditorAdapter, IFirepadConstructorOptions } from "@sagar0907/firepad";

const databaseAdapter: IDatabaseAdapter = ...; // Database Adapter instance

const editorAdapter: IEditorAdapter = ...; // Editor Adapter instance

const options: IFirepadConstructorOptions = {
   /** Unique Identifier for current User */
  userId: ..., // string or number
  /** Unique Hexadecimal color code for current User */
  userColor: ..., // string
  /** Name/Short Name of the current User (optional) */
  userName: ..., // string
  /** Default content of Firepad (optional) */
  defaultText: ..., // string
};

const firepad = new Firepad(databaseAdapter, editorAdapter, options);

Monaco as editor

If you use Monaco as an editor, we have an shorthand function fromMonaco to provide adapters and the binding out of the box with optional configuration object:

import { fromMonaco } from "@sagar0907/firepad";

const databaseRef: string | firebase.database.Reference = ...; // Path to Firebase Database or a Reference Object

const editor: monaco.editor.IEditor = ...; // Monaco Editor Instance

const firepad = fromMonaco(databaseRef, editor);

Writing Custom Adapters

To use Firepad with any other Editor, one simply need to write an implementation of Editor Adapter interface for that editor. This can be done like this:

import { IEditorAdapter } from "@sagar0907/firepad";

class MyEditorAdapter implements IEditorAdapter {
  ...
}

Similar thing can be done for Database as well by implementing IDatabaseAdapter interface. Keep in mind, you might also need to implement event handlers and event triggers depending upon nature of the adapters.

Dispose

After Firepad usecase is over, it is recommended to cleanup all the resources (e.g., memory, network etc.) using dispose() method. Note that, making any further API call after calling dispose() will result into error.

...

const firepad = new Firepad(databaseAdapter, editorAdapter, options);

...

firepad.dispose();

Development

We have used yarn as our package manager through out the project.

We use webpack-dev-server for local development environment and webpack for bundling. After installing all the dependencies including all the devDependencies and updating Database (Firebase) configuration, just do yarn start to kickoff development server. By default, the dev server opens in localhost:9000 but this can be configured by passing additional --port argument to the start command.

We use jest as both test runner and test suite to write unit tests. Doing yarn test should run all the testcases and publish coverage report.

Directories

  1. examples - All the working examples are kept and used for manual testing during development.
  2. src - Source directory for all the modules.
  3. test - Specs directory for all the modules.

Changelog

See CHANGELOG for more details.

Contributing

See CONTRIBUTING GUIDELINES for more details.

License

See LICENSE for more details.

Package Sidebar

Install

npm i @sagarjain0907/firepad

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

633 kB

Total Files

23

Last publish

Collaborators

  • sagar0907