Socket
Socket
Sign inDemoInstall

glow

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glow - npm Package Compare versions

Comparing version 0.0.2 to 1.0.0

cli.js

129

index.js

@@ -1,115 +0,16 @@

(function() {
var GritGetter, flow, grit, inBrowser,
__slice = Array.prototype.slice;
'use strict';
var ver = process.versions.node;
var majorVer = parseInt(ver.split('.')[0], 10);
inBrowser = function() {
return typeof module === 'undefined' || typeof exports === 'undefined' || typeof require === 'undefined';
};
grit = inBrowser() ? window.grit : require('grit');
flow = inBrowser() ? window.flow : require('heavy-flow');
GritGetter = (function() {
function GritGetter(dependencies) {
this.dependencies = dependencies.slice(0);
}
GritGetter.prototype.andGet = function(property) {
this.property = property;
return this;
};
GritGetter.prototype.from = function(modelGetter) {
var flowObject,
_this = this;
this.dependencies.push(function(finish, cancel) {
var model;
model = typeof modelGetter === 'function' ? modelGetter() : modelGetter;
return model.get(_this.property, function(err, data) {
if (err) {
return cancel("could not find " + _this.property);
} else {
return finish(data);
}
});
});
flowObject = flow.wait.apply(flow, this.dependencies);
flowObject.siphon = function(property) {
return new GritGetter([flowObject]).andGet(property).from(function() {
return flowObject.data();
});
};
return flowObject;
};
return GritGetter;
})();
/*
waitFor
-------
starts a fluid chain to asynchronously get a property from a model.
used like this:
`grit.waitFor(dependencies...).andGet(property).from(model)`
or:
`grit.waitFor.nothing().andGet(property).from(model)`
where dependencies... is an argument list of flow objects,
property is a property name, and model is either a model or
a function that will return a model if called once all dependencies
are satisifed.
the end of the chain returns a flow object that will attempt
to get the property once the dependencies are satisfied.
a convenient use case for this is getting models inside of a model.
for a stupid, simple example:
engine = grit.waitFor.nothing().andGet('engine').from(car)
part = grit.waitFor(exhaust).andGet('part').from -> engine.data()
piece = grit.waitFor(part).andGet('piece').from -> part.data()
note that the `siphon` method added to the grit Model class and
any flow objects that have been returned either from waitFor chains or
siphon calls makes getting properties considerably simpler. the
above can be rewritten:
engine = car.siphon('engine')
part = engine.siphon('part')
piece = part.siphon('piece')
remember that engine, part, and piece in the above are still flow
objects, not models themselves. to access the models once they've
been loaded, call engine.data(), etc.
*/
grit.waitFor = function() {
var dependencies;
dependencies = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return new GritGetter(dependencies);
};
grit.waitFor.nothing = function() {
return new GritGetter([]);
};
/*
siphon
------
instance method of all grit models and any flow objects
returned by a grit.waitFor chain or siphon call. takes a
property name.
returns a flow object that will immediately attempt to get the
property from the model.
*/
grit.Model.prototype.siphon = function(property) {
return grit.waitFor.nothing().andGet(property).from(this);
};
}).call(this);
if (majorVer < 4) {
console.error(
'Node version ' +
ver +
' is not supported in Bolt, please use Node.js 4.0 or higher.'
);
process.exit(1);
} else if (majorVer < 8) {
module.exports = require('./dist/legacy/index');
} else {
module.exports = require('./dist/modern/index');
}
{
"author": "Matt Baker",
"name": "glow",
"description": "A Grit plugin to make async property access simple. Based on Heavy Flow.",
"version": "0.0.2",
"repository": {
"type": "git",
"url": "git://github.com/reissbaker/glow.git"
"version": "1.0.0",
"description": "Make your Flow errors GLOW",
"main": "index.js",
"bin": {
"glow": "cli.js"
},
"main": "index.js",
"scripts": {
"test": "make test"
},
"repository": "https://github.com/thejameskyle/glow",
"author": "James Kyle <me@thejameskyle.com>",
"license": "MIT",
"keywords": ["flow", "cli", "bin", "errors", "reporter", "ui", "interface"],
"files": ["index.js", "cli.js"],
"engines": {
"node": ">=0.4.1"
"node": ">=8.4.0"
},
"dependencies": {
},
"devDependencies": {
"grit": ">=0.2.2",
"heavy-flow": ">=0.2.3",
"coffee-script": "1.2.0",
"mocha": "0.7.0",
"should": "0.4.2"
}
"scripts": {
"flow": "flow",
"test": "ava",
"format": "prettier --write **/*.{md,json,js}",
"clean": "rm -rf dist",
"build:legacy": "BABEL_ENV=legacy babel src -d dist/legacy",
"build:modern": "BABEL_ENV=modern babel src -d dist/modern",
"build": "yarn run clean && yarn build:legacy && yarn build:modern",
"prepublish": "yarn build",
"precommit": "lint-staged"
},
"dependencies": {
"@babel/code-frame": "^7.0.0-beta.38",
"babel-runtime": "^6.26.0",
"beeper": "^1.1.1",
"blessed": "^0.1.81",
"chalk": "^2.3.0",
"clear": "^0.0.1",
"find-up": "^2.1.0",
"lodash.debounce": "^4.0.8",
"meow": "^4.0.0",
"multimatch": "^2.1.0",
"read-pkg-up": "^3.0.0",
"signal-exit": "^3.0.2",
"spawndamnit": "^1.0.0",
"strip-ansi": "^4.0.0"
},
"peerDependencies": {
"flow-bin": "^0.63.1"
},
"devDependencies": {
"ava": "^0.24.0",
"babel-cli": "^6.26.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"babel-preset-flow": "^6.23.0",
"fixturez": "^1.1.0",
"flow-bin": "^0.63.1",
"husky": "^0.14.3",
"lint-staged": "^6.0.1",
"prettier": "^1.10.2"
},
"lint-staged": {
"*.{js,json,md}": ["prettier --write", "git add"]
}
}

@@ -1,95 +0,42 @@

GLOW
====
<img src="https://raw.githubusercontent.com/thejameskyle/glow/master/logo.jpg" alt="Glow logo"/>
A fluid flow-control plugin for Grit, based on Heavy Flow.
# Glow
Watch
-----
> Make your Flow errors GLOW
function alertNameAsync(model) {
var firstName = model.siphon('firstName');
var lastName = model.siphon('lastName');
## Installation
flow.wait(firstName, lastName, function(finish, cancel) {
alert('' + firstName.data() + ' ' + lastName.data());
finish();
});
}
```sh
# globally
yarn global add glow
# or in your project
yarn add --dev glow
```
Even if looking up `firstName` and `lastName` takes six async network
requests and a 3000 millisecond timeout, that alert will run. And despite
being non-blocking, it all looks beautifully synchronous.
<img src="https://raw.githubusercontent.com/thejameskyle/glow/master/video.jpg" alt="Preview"/>
You can also chain `siphon` from the flow control objects returned by `siphon`
calls. So, for example:
## Usage
function alertChildName(model) {
var firstName = model.siphon('child').siphon('firstName');
var lastName = model.siphon('child').siphon('lastName');
In your existing Flow project, instead of running:
flow.wait(firstName, lastName, function(finish, cancel) {
alert('' + firstName.data() + ' ' + lastName.data());
finish();
});
}
```sh
flow
```
Sometimes, though, you might not want to access a property until something
has happened, or dependencies have been satisfied. Glow gives you
a fluid interface for more fine-grained async access, even with multiple
dependencies.
Simply run:
function alertDependent(dependency1, dependency2, model) {
var mystery = grit.waitFor(dependency1, dependency2).andGet('ham').from(model);
```sh
glow
```
flow.wait(mystery, function(finish, cancel) {
alert('Request finished but what is this?\n' + mystery.data());
finish();
});
}
You can also filter errors down to a specific set of files by running:
`waitFor` chains return the same type of flow-control objects as `siphon`
calls do -- the only difference is that `waitFor` allows you to specify
dependencies fluidly. This means that `siphon` is available on any objects
returned from a `waitFor` chain, so that you can chain `siphon` calls onto
dependent chains. For example:
```sh
glow path/to/whatever
```
function chainedCall(dependency, model) {
var points = grit.waitFor(dependency).andGet('user').from(model).siphon('points');
flow.wait(points, function(finish, cancel) {
alert('' + points.data());
finish();
});
}
There's even an awesome watch mode:
API
---
* `siphon(property)` is a method added to Grit's `Model` class. `siphon` returns a
Heavy Flow flow-control object, much like what you'd get from a `flow.wait()` call.
`siphon` objects will run immediately, with no dependencies, and will finish as soon
as the given `property` is successfully fetched from the model. If the property access
fails, the flow control object will cancel. `siphon` is also available directly from
flow control objects created by a `siphon` or Glow `waitFor` fluid interface call,
so that you can chain `siphon` calls together to get properties from child models.
* `waitFor(dependencies...).andGet(property).from(model)` is the fluid interface
for fine-grained access of properties on models. Like `siphon`, the fluid chain
will return a Heavy Flow flow-control object; however, it will only run once all
dependencies have been satisfied. `siphon` is available on any flow-control objects
returned from a `waitFor` chain. The `model` argument can be a Grit `Model` (or
subclass), but can also be a function that returns a model when called. If a function
is passed in, the function will only be called _after_ the dependencies are satisfied,
which allows you to use data from the dependencies inside the model function.
* `waitFor.nothing().andGet(property).from(model)` is similar to the above, but
does not wait for any dependencies. The only difference between this and the much
more concise `siphon(property)` method is that the `model` argument can be a
function that returns a model, like the above, rather than a model accessible at
definition time.
LICENSE
=======
GPL v3. See LICENSE.txt and "GNU General Public License".txt for details.
```sh
glow --watch
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc