[0.0.1] Migrate SubscribableEvents from ReactXP to standalone package

This commit is contained in:
Brent Erickson 2017-05-09 16:11:26 -07:00
Родитель 8304cb08d2
Коммит 4d0c670b85
5 изменённых файлов: 213 добавлений и 237 удалений

272
.gitignore поставляемый
Просмотреть файл

@ -1,252 +1,50 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
# Logs
logs
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
npm-debug.log*
# Chutzpah Test files
_Chutzpah*
# Runtime data
pids
*.pid
*.seed
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Coverage directory used by tools like istanbul
coverage
# TFS 2012 Local Workspace
$tf/
# nyc test coverage
.nyc_output
# Guidance Automation Toolkit
*.gpState
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# node-waf configuration
.lock-wscript
# JustCode is a .NET coding add-in
.JustCode
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# TeamCity is a build add-in
_TeamCity*
# Dependency directories
node_modules
/samples/*/node_modules
# DotCover is a Code Coverage Tool
*.dotCover
# Optional npm cache directory
.npm
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# Optional REPL history
.node_repl_history
# MightyMoose
*.mm.*
AutoTest.Net/
# Build artifacts
/src/.vs
/src/bin
/src/obj
/dist
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# Miscellaneous user files
*.user
.vscode
.DS_STORE
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml

35
package.json Normal file
Просмотреть файл

@ -0,0 +1,35 @@
{
"name": "subscribableevent",
"version": "0.0.1",
"description": "A simple strongly-typed pub/sub/fire eventing system. Edit",
"main": "dist/SubscribableEvent.js",
"scripts": {
"tslint": "tslint --rules-dir './node_modules/tslint-microsoft-contrib' ./src/**/*.ts",
"prepublish": "npm run tslint && tsc",
"build": "npm run tslint && tsc"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Microsoft/SubscribableEvent.git"
},
"keywords": [
"Typescript",
"Eventing",
"Subscribable"
],
"author": "ReactXP Team <reactxp@microsoft.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/Microsoft/SubscribableEvent/issues"
},
"homepage": "https://github.com/Microsoft/SubscribableEvent#readme",
"dependencies": {
"@types/lodash": "^4.14.64",
"lodash": "^4.17.4"
},
"devDependencies": {
"tslint": "^5.2.0",
"tslint-microsoft-contrib": "^4.0.1",
"typescript": "^2.3.2"
}
}

59
src/SubscribableEvent.ts Normal file
Просмотреть файл

@ -0,0 +1,59 @@
/**
* SubscribableEvent.ts
*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT license.
*
* A simple strongly-typed pub/sub/fire eventing system.
*/
import clone = require('lodash/clone');
import pull = require('lodash/pull');
export class SubscriptionToken {
constructor(private _event: SubscribableEvent<any>,
private _callback: (...args: any[]) => boolean|void) {
}
unsubscribe() {
this._event.unsubscribe(this._callback);
}
}
export class SubscribableEvent<F extends { (...args: any[]): boolean|void }> {
private _subscribers: Function[];
constructor() {
this._subscribers = [];
}
dispose() {
this._subscribers = [];
}
subscribe(callback: F): SubscriptionToken {
this._subscribers.push(callback);
return new SubscriptionToken(this, callback);
}
unsubscribe(callback: F) {
pull(this._subscribers, callback);
}
fire: F = <any> ((...args: any[]) => {
// Clone the array so original can be modified by handlers.
const subs = clone(this._subscribers);
// Execute handlers in the reverse order in which they
// were registered.
for (let i = subs.length - 1; i >= 0; i--) {
if (subs[i].apply(null, args)) {
// If the value was handled, early out.
return true;
}
}
return false;
});
}

23
tsconfig.json Normal file
Просмотреть файл

@ -0,0 +1,23 @@
{
"compilerOptions": {
"declaration": true,
"noResolve": false,
"module": "commonjs",
"target": "es5",
"experimentalDecorators": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"outDir": "dist/"
},
"filesGlob": [
"src/**/*{ts,tsx}"
],
"exclude": [
"dist",
"node_modules"
]
}

61
tslint.json Normal file
Просмотреть файл

@ -0,0 +1,61 @@
{
"rules": {
"align": [true, "statements"],
"class-name": true,
"curly": true,
"eofline": true,
"forin": true,
"indent": [true, "spaces"],
"label-position": true,
"max-line-length": [ true, 140 ],
"no-arg": true,
"no-bitwise": false,
"no-conditional-assignment": true,
"no-consecutive-blank-lines": [true],
"no-construct": true,
"no-debugger": true,
"no-duplicate-variable": true,
"no-empty": true,
"no-eval": true,
"no-inferrable-types": [true],
"no-switch-case-fall-through": true,
"no-trailing-whitespace": false,
"no-unused-expression": true,
"one-line": [true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
"quotemark": [true, "single"],
"radix": true,
"semicolon": [true],
"triple-equals": [true, "allow-null-check"],
"variable-name": false,
"whitespace": [true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
],
"no-banned-terms": true,
"no-delete-expression": true,
"no-document-domain": true,
"no-disable-auto-sanitization": true,
"no-duplicate-parameter-names": true,
"no-exec-script": true,
"no-function-constructor-with-string-args": true,
"no-octal-literal": true,
"no-reserved-keywords": false,
"no-string-based-set-immediate": true,
"no-string-based-set-interval": true,
"no-string-based-set-timeout": true,
"react-no-dangerous-html":true,
"no-inner-html":true,
"no-document-write":true,
"no-var-requires": true,
"no-var-keyword": true
}
}