Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ec12061
Showing
11 changed files
with
399 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"optional": ["runtime"], | ||
"stage": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
; editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.json] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "standard", | ||
"parser": "babel-eslint", | ||
"env": { | ||
"browser": true, | ||
"node": true, | ||
"mocha": true, | ||
"es6": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
coverage | ||
lib | ||
node_modules | ||
|
||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
language: node_js | ||
node_js: | ||
- "0.10" | ||
- "0.11" | ||
- "0.12" | ||
- "4" | ||
before_install: | ||
- export DISPLAY=:99.0 | ||
- sh -e /etc/init.d/xvfb start | ||
install: | ||
- npm install | ||
env: | ||
- TEST_SUITE=coveralls | ||
- TEST_SUITE=lint | ||
- TEST_SUITE=test | ||
script: "npm run $TEST_SUITE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Kirill Fomichev | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# sync-mixin | ||
|
||
[![build status](https://img.shields.io/travis/fanatid/sync-mixin.svg?branch=master&style=flat-square)](http://travis-ci.org/fanatid/sync-mixin) | ||
[![Coverage Status](https://img.shields.io/coveralls/fanatid/sync-mixin.svg?style=flat-square)](https://coveralls.io/r/fanatid/sync-mixin) | ||
[![Dependency status](https://img.shields.io/david/fanatid/sync-mixin.svg?style=flat-square)](https://david-dm.org/fanatid/sync-mixin#info=dependencies) | ||
[![Dev Dependency status](https://img.shields.io/david/fanatid/sync-mixin.svg?style=flat-square)](https://david-dm.org/fanatid/sync-mixin#info=devDependencies) | ||
|
||
[![NPM](https://nodei.co/npm/sync-mixin.png?downloads=true)](https://www.npmjs.com/package/sync-mixin) | ||
[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard) | ||
|
||
## Installation | ||
|
||
``` | ||
npm install sync-mixin | ||
``` | ||
|
||
## API | ||
|
||
### _getSyncCount() | ||
|
||
**return**: `number` | ||
|
||
### _setSyncCount() | ||
|
||
* `number` value | ||
|
||
### _syncEnter() | ||
|
||
### _syncExit() | ||
|
||
### _withSync() | ||
|
||
* `function` fn | ||
|
||
**return**: `Promise` | ||
|
||
### _syncExitAll() | ||
|
||
### isSyncing() | ||
|
||
## Examples | ||
|
||
### | ||
|
||
```js | ||
import { mixin } from 'core-decorators' | ||
import SyncMixin from 'sync-mixin' | ||
|
||
@mixin(SyncMixin) | ||
class Process { | ||
run () { | ||
return this._withSync(() => { | ||
// some code that require time for execution | ||
}) | ||
} | ||
} | ||
|
||
let process = new Process() | ||
process.on('syncStart', () => console.log('Syncronization started!')) | ||
process.on('syncStop', () => console.log('Syncronization finished!')) | ||
setInterval(::process.run, 60 * 1000) | ||
``` | ||
|
||
## License | ||
|
||
Code released under [the MIT license](LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module.exports = function (config) { | ||
config.set({ | ||
frameworks: ['browserify', 'detectBrowsers', 'mocha'], | ||
files: [ | ||
'node_modules/babel-core/browser-polyfill.js', | ||
'test/*.js' | ||
], | ||
preprocessors: { | ||
'test/*.js': ['browserify'] | ||
}, | ||
singleRun: true, | ||
plugins: [ | ||
'karma-browserify', | ||
'karma-chrome-launcher', | ||
'karma-firefox-launcher', | ||
'karma-detect-browsers', | ||
'karma-mocha' | ||
], | ||
browserify: { | ||
debug: true, | ||
transform: [ | ||
['babelify'] | ||
] | ||
}, | ||
detectBrowsers: { | ||
enabled: true, | ||
usePhantomJS: false, | ||
postDetection: function (availableBrowser) { | ||
if (process.env.TRAVIS) { | ||
return ['Firefox'] | ||
} | ||
|
||
var browsers = ['Chrome', 'Firefox'] | ||
return browsers.filter(function (browser) { | ||
return availableBrowser.indexOf(browser) !== -1 | ||
}) | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"name": "sync-mixin", | ||
"version": "1.0.0", | ||
"description": "Emit events in classes about sync", | ||
"keywords": [ | ||
"syncing", | ||
"mixin" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/fanatid/sync-mixin/issues" | ||
}, | ||
"license": "MIT", | ||
"author": { | ||
"name": "Kirill Fomichev", | ||
"email": "fanatid@ya.ru" | ||
}, | ||
"files": [ | ||
"lib", | ||
"src", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"main": "./lib/index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fanatid/sync-mixin.git" | ||
}, | ||
"scripts": { | ||
"prepublish": "npm run clean && npm run compile", | ||
"compile": "babel -d lib src", | ||
"compile:watch": "babel -d lib src -w", | ||
"coverage": "istanbul cover _mocha -- --compilers js:babel/register test/*.js", | ||
"coveralls": "npm run coverage && coveralls <coverage/lcov.info", | ||
"clean": "rm -f lib/*", | ||
"lint": "eslint src test", | ||
"test": "npm run test:node && npm run test:browser", | ||
"test:browser": "karma start karma.conf.js", | ||
"test:node": "istanbul test mocha -- --compilers js:babel/register --reporter spec test/*.js" | ||
}, | ||
"dependencies": { | ||
"babel-runtime": "^5.8.25" | ||
}, | ||
"devDependencies": { | ||
"babel": "^5.8.23", | ||
"babel-core": "^5.8.25", | ||
"babel-eslint": "^4.1.3", | ||
"babelify": "^6.4.0", | ||
"chai": "^3.4.0", | ||
"core-decorators": "^0.8.1", | ||
"coveralls": "^2.11.4", | ||
"eslint": "^1.7.3", | ||
"eslint-config-standard": "^4.4.0", | ||
"eslint-plugin-standard": "^1.2.0", | ||
"istanbul": "^0.4.0", | ||
"karma": "^0.13.14", | ||
"karma-browserify": "^4.4.0", | ||
"karma-chrome-launcher": "^0.2.1", | ||
"karma-detect-browsers": "^2.0.2", | ||
"karma-firefox-launcher": "^0.1.6", | ||
"karma-mocha": "^0.2.0", | ||
"mocha": "^2.3.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
export default { | ||
_getSyncCount () { | ||
if (this._syncCount === undefined) { | ||
this._syncCount = 0 | ||
} | ||
|
||
return this._syncCount | ||
}, | ||
|
||
_setSyncCount (value) { | ||
this._syncCount = value | ||
|
||
if (value === 0) { | ||
return this.emit('syncStop') | ||
} | ||
|
||
if (value === 1) { | ||
return this.emit('syncStart') | ||
} | ||
}, | ||
|
||
_syncEnter () { | ||
this._setSyncCount(this._getSyncCount() + 1) | ||
}, | ||
|
||
_syncExit () { | ||
this._setSyncCount(this._getSyncCount() - 1) | ||
}, | ||
|
||
async _withSync (fn) { | ||
this._syncEnter() | ||
try { | ||
return await fn() | ||
} finally { | ||
this._syncExit() | ||
} | ||
}, | ||
|
||
_syncExitAll () { | ||
this._setSyncCount(0) | ||
}, | ||
|
||
isSyncing () { | ||
return this._getSyncCount() > 0 | ||
} | ||
} |
Oops, something went wrong.