# onfire.js **Repository Path**: hustcc/onfire.js ## Basic Information - **Project Name**: onfire.js - **Description**: :gun: onfire.js is a simple events dispatcher subscribe / publish library (just 0.7kb). simple and usefull. - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 3 - **Created**: 2016-07-15 - **Last Updated**: 2023-06-15 ## Categories & Tags **Categories**: javascript-toolkits **Tags**: None ## README # onfire.js > **onfire.js** is a simple events dispatcher library (just `0.9kb`). simple and usefull. Can be used in: - simple events dispatcher. - `Cross-component communication` of react / vue.js / angular. - evnets subscribe and publish. Live DEMO [**here**](http://git.hust.cc/onfire.js). 中文版说明文档[点这里](README_zh.md)。 [![Build Status](https://travis-ci.org/hustcc/onfire.js.svg?branch=master)](https://travis-ci.org/hustcc/onfire.js) [![npm](https://img.shields.io/npm/v/onfire.js.svg?style=flat-square)](https://www.npmjs.com/package/onfire.js) [![npm](https://img.shields.io/npm/dt/onfire.js.svg?style=flat-square)](https://www.npmjs.com/package/onfire.js) [![npm](https://img.shields.io/npm/l/onfire.js.svg?style=flat-square)](https://www.npmjs.com/package/onfire.js) # API method **1. `on(event_name, callback, context)`** Binding / subscribe the `event_name` with `callback`. when has event named `event_name` fired, `callback` function will process. The function will return the `eventObj`, which can be used to cancel bind with API `un(eventObj)`. **2. `one(event_name, callback, context)`** Binding / subscribe the `event_name` with `callback` only once. And it is will timeout after Trigger. `Only can be Trigger once`, then it will be deleted automation. **3. `fire(event_name, data1, data2, data3, ...)`** `Async` Trigger / subscribe the event named `event_name`, and with `datas` as the input of `callback` function. **4. `fireSync(event_name, data1, data2, ...)`** `Sync` Trigger / subscribe the event named `event_name`, and with `datas` as the input of `callback` function. **5. `un(eventObj / event_name / function)`** Cancel binding event. You can unbinding a event Object, or just unbinding a event_name, or unbind the callback function. Get the exist events Array. **6. `clear()`** Clear all the event. # Detail Usage **1. import library** Install javascript library. > npm install onfire.js You can import it with `