Skip to content

Commit

Permalink
Add npm support
Browse files Browse the repository at this point in the history
Run `npm publish` each time a version is released.
  • Loading branch information
necolas committed Oct 25, 2014
1 parent 86c9d1c commit f462336
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 150 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@ properties of a global variable, `flight`.
<script src="http://flightjs.github.io/release/latest/flight.min.js"></script>
```

Using [npm](https://www.npmjs.org/):

```
npm install --save flightjs
```

Using [Bower](http://bower.io/):

```
bower install --save flight
```

You will have to include [jQuery](http://jquery.com) and use a module loader
with support for AMD, like [Webpack](http://webpack.github.io/) or
[Require.js](http://requirejs.org/).
You will have to load [jQuery](http://jquery.com) in your application.

## Why Flight?

Expand Down
82 changes: 37 additions & 45 deletions doc/advice_api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Advice API

In Flight, advice is a mixin (`lib/advice.js`) that defines `before`, `after`
In Flight, `advice` is a mixin (`lib/advice.js`) that defines `before`, `after`
and `around` methods.

These can be used to modify existing functions by adding custom code. All
Expand All @@ -23,15 +23,13 @@ The name of the existing function (`existingFunc`) you want to augment.
The function to be invoked before `existingFunc`.

```js
define(function() {
function withDrama() {
this.before('announce', function() {
clearThroat();
});
}
function withDrama() {
this.before('announce', function() {
clearThroat();
});
}

return withDrama;
});
return withDrama;
```

<a name="this.after"></a>
Expand All @@ -48,15 +46,13 @@ The name of the existing function (`existingFunc`) you want to augment.
The function to be invoked after `existingFunc`.

```js
define(function() {
function withDrama() {
this.after('leaving', function() {
slamDoor();
});
}
function withDrama() {
this.after('leaving', function() {
slamDoor();
});
}

return withDrama;
});
return withDrama;
```

<a name="this.around"></a>
Expand All @@ -79,17 +75,15 @@ it can be referenced. If the custom function does not call the existing
function then it will replace that function instead of surrounding it:

```js
define(function() {
function withDrama() {
this.around('announce', function(basicAnnounce) {
clearThroat();
basicAnnounce();
bow();
});
}
function withDrama() {
this.around('announce', function(basicAnnounce) {
clearThroat();
basicAnnounce();
bow();
});
}

return withDrama;
});
return withDrama;
```

<a name="advice.withAdvice"></a>
Expand All @@ -99,29 +93,27 @@ Advice can be mixed in to non-components using the compose module:

```js
// a simple module: 'test/myObj'
define(function() {
var myObj = {
print: function() {
console.log("hello");
}
};

return myObj;
});

var myObj = {
print: function() {
console.log("hello");
}
};

return myObj;
```

```js
// import myObj and augment it
define(function(require) {
var flight = require('flight');
var myObj = require('test/myObj');

// add advice functions to myObj
flight.advice.withAdvice.call(myObj);
var flight = require('flightjs');
var myObj = require('test/myObj');

// augment print function
myObj.after('print', function() {
console.log("world");
});
// add advice functions to myObj
flight.advice.withAdvice.call(myObj);

// augment print function
myObj.after('print', function() {
console.log('world');
});
```
76 changes: 34 additions & 42 deletions doc/component_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,21 @@ Component:
```js
/* my_simple_component.js */

define(function(require) {
var flight = require('flight');
var withMyMixin = require('with_my_mixin');

return flight.component(mySimpleComponent, withMyMixin);

// this Component's custom properties
function mySimpleComponent() {
this.doSomething = function() {
//...
};

this.doSomethingElse = function() {
//...
};
}
});
var flight = require('flightjs');
var withMyMixin = require('with_my_mixin');

module.exports = flight.component(mySimpleComponent, withMyMixin);

// this Component's custom properties
function mySimpleComponent() {
this.doSomething = function() {
//...
};

this.doSomethingElse = function() {
//...
};
}
```

Components make no assumptions about the existence of other objects. If you
Expand All @@ -63,20 +61,18 @@ method deletes every instance of every Component and all their event
bindings.

```js
define(function(require) {
var flight = require('flight');
var flight = require('flightjs');

return flight.component(navigationMenu);
module.exports = flight.component(navigationMenu);

function navigationMenu() {
this.resetEverything = function() {
// remove every component instance and all event listeners
flight.component.teardownAll();
};
function navigationMenu() {
this.resetEverything = function() {
// remove every component instance and all event listeners
flight.component.teardownAll();
};

// ...
}
});
// ...
}
```

<a name="Component.attachTo"></a>
Expand All @@ -103,13 +99,11 @@ couple of selectors which will override the values defined in the Component's
```js
/* attach an inbox component to a node with id 'inbox'*/

define(function(require) {
var Inbox = require('components/inbox');
var Inbox = require('components/inbox');

Inbox.attachTo('#inbox', {
'nextPageSelector': '#nextPage',
'previousPageSelector': '#previousPage',
});
Inbox.attachTo('#inbox', {
'nextPageSelector': '#nextPage',
'previousPageSelector': '#previousPage',
});
```

Expand All @@ -125,11 +119,11 @@ the `$node` property.)

```js
this.setId = function(n) {
this.node.id = n;
this.node.id = n;
};

this.hideComponent = function() {
this.$node.hide();
this.$node.hide();
};
```

Expand All @@ -140,11 +134,9 @@ On a Component constructor this method deletes every instance of that Component
type and all their event bindings.

```js
define(function(require) {
var NavigationMenu = require('ui/navigationMenu');
var NavigationMenu = require('ui/navigationMenu');

// ...
// remove all instances of NavigationMenu and all their event bindings
NavigationMenu.teardownAll();
});
// ...
// remove all instances of NavigationMenu and all their event bindings
NavigationMenu.teardownAll();
```
Loading

0 comments on commit f462336

Please sign in to comment.