Skip to content

Commit

Permalink
docs(api): update constructor docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Nov 15, 2016
1 parent 9f7cb7c commit 0ada8b2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 38 deletions.
43 changes: 21 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# minibase [![NPM version](https://img.shields.io/npm/v/minibase.svg?style=flat)](https://www.npmjs.com/package/minibase) [![NPM downloads](https://img.shields.io/npm/dm/minibase.svg?style=flat)](https://npmjs.org/package/minibase) [![npm total downloads][downloads-img]][downloads-url]

> MiniBase is minimalist approach to Base - @node-base, the awesome framework. Foundation for building complex APIs with small units called plugins. Works well with most of the already existing [base][] plugins.
> Minimalist alternative for Base. Build complex APIs with small units called plugins. Works well with most of the already existing [base][] plugins.
[![code climate][codeclimate-img]][codeclimate-url] [![standard code style][standard-img]][standard-url] [![travis build status][travis-img]][travis-url] [![Windows Build Status](https://img.shields.io/appveyor/ci/node-minibase/minibase.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/node-minibase/minibase) [![coverage status][coveralls-img]][coveralls-url] [![dependency status][david-img]][david-url]

Expand Down Expand Up @@ -54,39 +54,38 @@ const minibase = require('minibase')

## API

### [MiniBase](index.js#L47)
### [MiniBase](index.js#L46)
> Creates an instance of `MiniBase` with optional `options` object - if given, otherwise the `minibase.options` defaults to empty object. _**Never throws - emit events!™**_
**Params**

* `[options]` **{Object}**: optional, pass `silent: true` to not add default error listener
* `[options]` **{Object}**: optional, written to `this.options`

**Example**

```js
const MiniBase = require('minibase').MiniBase

// main export is instance
const app = require('minibase')

// when `silent: true` it will not add
// the default event listener to `error` event
const minibase = MiniBase({ silent: true })
app.once('error', (err) => {
console.log('error:', err)
})

// nothing is printed, until you add
// listener `.on('error', fn)`
minibase.use(() => {
throw new Error('foo bar')
app.use((self) => {
// this === self === app
console.log(self.use) // => 'function'
console.log(self.define) // => 'function'
self.define('foo', 'bar')
})

// if you work with defaults
// you will get this error printed
// because the default error handler
app.use(function () {
console.log(this.options.silent) // => undefined
throw new Error('default error handler works')
app.use(() => {
throw new Error('qux')
})
```

### [.delegate](index.js#L129)
### [.delegate](index.js#L128)
> Copy properties from `provider` to `this` instance of `MiniBase`, using [delegate-properties][] lib.
**Params**
Expand Down Expand Up @@ -119,7 +118,7 @@ console.log(minibase.foo) // => 'bar'
console.log(minibase.qux('kitty!')) // => 'hello kitty!'
```

### [.define](index.js#L183)
### [.define](index.js#L182)
> Used for adding non-enumerable property `key` with `value` on the instance, using [define-property][] lib.
**Params**
Expand Down Expand Up @@ -166,7 +165,7 @@ console.log(minimist.cache.baz) // => { a: 'b' }
console.log(minimist.cache.qux) // => 123
```

### [.use](index.js#L218)
### [.use](index.js#L217)
> Define a synchronous plugin `fn` function to be called immediately upon init. _**Never throws - emit events!™**_
**Params**
Expand Down Expand Up @@ -196,7 +195,7 @@ app
})
```

### [#delegate](index.js#L263)
### [#delegate](index.js#L262)
> Static method to delegate properties from `provider` to `receiver` and make them non-enumerable.
See [delegate-properties][] for more details, it is exact mirror.
Expand All @@ -221,7 +220,7 @@ console.log(obj.foo) // => 'bar'
console.log(obj.qux) // => 123
```

### [#define](index.js#L290)
### [#define](index.js#L289)
> Static method to define a non-enumerable property on an object.
See [define-property][] for more details, it is exact mirror.
Expand All @@ -245,7 +244,7 @@ console.log(obj.foo) // => 123
console.log(obj.bar()) // => 'qux'
```

### [#extend](index.js#L327)
### [#extend](index.js#L326)
> Static method for inheriting the prototype and static methods of the `MiniBase` class. This method greatly simplifies the process of creating inheritance-based applications.
See [static-extend][] for more details.
Expand Down
27 changes: 13 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,27 @@ var utils = require('./utils')
*
* ```js
* const MiniBase = require('minibase').MiniBase
*
* // main export is instance
* const app = require('minibase')
*
* // when `silent: true` it will not add
* // the default event listener to `error` event
* const minibase = MiniBase({ silent: true })
* app.once('error', (err) => {
* console.log('error:', err)
* })
*
* // nothing is printed, until you add
* // listener `.on('error', fn)`
* minibase.use(() => {
* throw new Error('foo bar')
* app.use((self) => {
* // this === self === app
* console.log(self.use) // => 'function'
* console.log(self.define) // => 'function'
* self.define('foo', 'bar')
* })
*
* // if you work with defaults
* // you will get this error printed
* // because the default error handler
* app.use(function () {
* console.log(this.options.silent) // => undefined
* throw new Error('default error handler works')
* app.use(() => {
* throw new Error('qux')
* })
* ```
*
* @param {Object} `[options]` optional, pass `silent: true` to not add default error listener
* @param {Object} `[options]` optional, written to `this.options`
* @api public
*/

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "minibase",
"version": "0.4.6",
"description": "MiniBase is minimalist approach to Base - @node-base, the awesome framework. Foundation for building complex APIs with small units called plugins. Works well with most of the already existing [base][] plugins.",
"description": "Minimalist alternative for Base. Build complex APIs with small units called plugins. Works well with most of the already existing [base][] plugins.",
"repository": "node-minibase/minibase",
"author": "Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)",
"precommit.silent": true,
Expand Down Expand Up @@ -140,4 +140,4 @@
"reflinks": true
}
}
}
}

0 comments on commit 0ada8b2

Please sign in to comment.