Skip to content

2.0.0 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .babelrc

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
node_modules/
.nyc_output/
coverage/
dist/

*.log
.DS_Store
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
src/
.babelrc
tsconfig.json
rollup.config.js
.travis.yml
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: node_js
node_js:
- "node"
- "lts/*"
- "7"
- "6"
after_success:
- npm run coveralls
82 changes: 42 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ npm install --save orcajs
Import that wrapper for use throughout your application:

```js
import app from 'orcajs';
app.registerAction('*', () => { console.log("test"); });
import app from "orcajs";
app.registerAction("*", () => {
console.log("test");
});
app.run(); // => test
```

Expand All @@ -29,14 +31,14 @@ In a perfect world, you'd have a small, perfect javascript bundle, built of magi
But we know that's not the world you live in. If you're working on anything like any of the web apps we've seen over the past 5 years, you've got some frankenstein monster that's half legacy jQuery and half "I learned this in a weekend" Angular --- and worse, you've probably got something like this:

```js
if ($('body').hasClass('special-page')) {
// execute code that only works on this page here.
// Don't execute it anywhere else or everything
// will break.
if ($("body").hasClass("special-page")) {
// execute code that only works on this page here.
// Don't execute it anywhere else or everything
// will break.
}

if ( $('#special-div').length > 0 ) {
// this will break if #special-div is not present
if ($("#special-div").length > 0) {
// this will break if #special-div is not present
}
```

Expand All @@ -47,80 +49,80 @@ If that looks familiar, then `orca` is for you.
`orca` lets you set up ordered an ordered system of callbacks for dividing your code into discretely executing chunks. This lets you bundle all your code into a single JS file, but limit code to just to the pages they're used on.

```js
import app from 'orcajs';
import app from "orcajs";

// Define Callbacks
function all() { console.log("All"); }
function foo() { console.log("Foo"); }
function bar() { console.log("Bar"); }
const all = () => console.log("All");
const foo = () => console.log("Foo");
const bar = () => console.log("Bar");

// Register Actions
app.registerGlobalAction(all);
app.registerAction('foo', foo);
app.registerAction('bar', bar);
app.registerAction("foo", foo);
app.registerAction("bar", bar);

app.run('foo'); // => log All, Foo
app.run("foo"); // => log All, Foo
```

## Namespacing

Namespacing allows you to run code in a structured way. Calling `run` with a namespace will run only the actions in that namespace.
Namespacing allows you to run code in a structured way. Calling `run` with a scope will run only the actions in that scope.

```js
app.registerGlobalAction(all); // global namespace
app.registerAction('foo', foo); // foo namespace
app.registerAction('bar', bar); // bar namespace
app.registerGlobalAction(all); // global scope
app.registerAction("foo", foo); // foo scope
app.registerAction("bar", bar); // bar scope

app.run('foo'); // runs `all` and `foo`, but not `bar`
app.run("foo"); // runs `all` and `foo`, but not `bar`
```

### Nesting

Namespaces can be nested with the `.` character:
scopes can be nested with the `.` character:

```js
app.registerAction('foo.bar', fooBar);
app.registerAction('foo.baz', fooBaz);
app.registerAction("foo.bar", fooBar);
app.registerAction("foo.baz", fooBaz);

app.run('foo'); // runs `fooBar` and `fooBaz`
app.run('foo.bar'); // runs `fooBar`, but not `fooBaz`
app.run("foo"); // runs `fooBar` and `fooBaz`
app.run("foo.bar"); // runs `fooBar`, but not `fooBaz`
```

### Executing Multiple Namespaces
### Executing Multiple scopes

Multiple namespaces can be run at once:
Multiple scopes can be run at once:

```js
app.run(['foo', 'bar']);
app.run(["foo", "bar"]);
```

### Excluding Callbacks from Namespaces
### Excluding Callbacks from scopes

Callbacks can be excluded from specific namespaces:
Callbacks can be excluded from specific scopes:

```js
app.registerGlobalAction(foo, {excludes: ['bar']});
app.registerGlobalAction(foo, { excludes: ["bar"] });

app.run(); // runs `foo`
app.run('foo'); // runs `foo`
app.run('bar'); // does not run `foo`
app.run(); // runs `foo`
app.run("foo"); // runs `foo`
app.run("bar"); // does not run `foo`
```

If you'd like to run a namespace, but exclude global actions, you can pass a second argument to `run`:
If you'd like to run a scope, but exclude global actions, you can pass a second argument to `run`:

```js
app.registerGlobalAction(foo);
app.registerAction('bar', baz);
app.registerAction("bar", baz);

app.run(); // runs `foo`
app.run('bar', {runGlobals: false}); // does not run `foo`
app.run(); // runs `foo`
app.run("bar", { runGlobals: false }); // does not run `foo`
```

## Priority

Sometimes sequencing can be important when executing discrete blocks of code. There's an optional third parameter which can be passed to `registerAction`, which will set the priority. Actions will be run in priority order from high to low.

```js
app.registerGlobalAction(foo, {priority: 0});
app.registerGlobalAction(bar, {priority: 5}); // this will run before foo
app.registerGlobalAction(foo, { priority: 0 });
app.registerGlobalAction(bar, { priority: 5 }); // this will run before foo
```
Loading