Comparing version 0.0.2 to 1.0.0
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"] | ||
} | ||
} |
109
README.md
@@ -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 | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
0
100
1
4369
15
12
5
32
43
1
2
+ Addedbabel-runtime@^6.26.0
+ Addedbeeper@^1.1.1
+ Addedblessed@^0.1.81
+ Addedchalk@^2.3.0
+ Addedclear@^0.0.1
+ Addedfind-up@^2.1.0
+ Addedlodash.debounce@^4.0.8
+ Addedmeow@^4.0.0
+ Addedmultimatch@^2.1.0
+ Addedread-pkg-up@^3.0.0
+ Addedsignal-exit@^3.0.2
+ Addedspawndamnit@^1.0.0
+ Addedstrip-ansi@^4.0.0
+ Added@babel/code-frame@7.24.7(transitive)
+ Added@babel/helper-validator-identifier@7.24.7(transitive)
+ Added@babel/highlight@7.24.7(transitive)
+ Addedansi-regex@3.0.1(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedarray-differ@1.0.0(transitive)
+ Addedarray-find-index@1.0.2(transitive)
+ Addedarray-union@1.0.2(transitive)
+ Addedarray-uniq@1.0.3(transitive)
+ Addedarrify@1.0.1(transitive)
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbeeper@1.1.1(transitive)
+ Addedblessed@0.1.81(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcamelcase@4.1.0(transitive)
+ Addedcamelcase-keys@4.2.0(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedclear@0.0.1(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addedcross-spawn@5.1.0(transitive)
+ Addedcurrently-unhandled@0.4.1(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addeddecamelize-keys@1.1.1(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfind-up@2.1.0(transitive)
+ Addedflow-bin@0.63.1(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedindent-string@3.2.0(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-plain-obj@1.1.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjson-parse-better-errors@1.0.2(transitive)
+ Addedload-json-file@4.0.0(transitive)
+ Addedlocate-path@2.0.0(transitive)
+ Addedlodash.debounce@4.0.8(transitive)
+ Addedloud-rejection@1.6.0(transitive)
+ Addedlru-cache@4.1.5(transitive)
+ Addedmap-obj@1.0.12.0.0(transitive)
+ Addedmeow@4.0.1(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedminimist-options@3.0.2(transitive)
+ Addedmultimatch@2.1.0(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addedp-limit@1.3.0(transitive)
+ Addedp-locate@2.0.0(transitive)
+ Addedp-try@1.0.0(transitive)
+ Addedparse-json@4.0.0(transitive)
+ Addedpath-exists@3.0.0(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@3.0.0(transitive)
+ Addedpicocolors@1.1.0(transitive)
+ Addedpify@3.0.0(transitive)
+ Addedpseudomap@1.0.2(transitive)
+ Addedquick-lru@1.1.0(transitive)
+ Addedread-pkg@3.0.0(transitive)
+ Addedread-pkg-up@3.0.0(transitive)
+ Addedredent@2.0.0(transitive)
+ Addedregenerator-runtime@0.11.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedspawndamnit@1.0.0(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedstrip-ansi@4.0.0(transitive)
+ Addedstrip-bom@3.0.0(transitive)
+ Addedstrip-indent@2.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtrim-newlines@2.0.0(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedyallist@2.1.2(transitive)