diff --git a/.gitignore b/.gitignore index 79fc551..781f9e1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ npm-debug.log* yarn-debug.log* yarn-error.log* +dist/* _book/* # Runtime data diff --git a/dist/accessor_decorators.js b/dist/accessor_decorators.js deleted file mode 100644 index b12c0e3..0000000 --- a/dist/accessor_decorators.js +++ /dev/null @@ -1,43 +0,0 @@ -'use strict'; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -var __metadata = (this && this.__metadata) || function (k, v) { - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); -}; -// 访问器装饰器,Accessor Decorator -var Point = /** @class */ (function () { - function Point(x, y) { - this._x = x; - this._y = y; - } - Object.defineProperty(Point.prototype, "x", { - get: function () { return this._x; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Point.prototype, "y", { - get: function () { return this._y; }, - enumerable: true, - configurable: true - }); - __decorate([ - configurable(false), - __metadata("design:type", Object), - __metadata("design:paramtypes", []) - ], Point.prototype, "x", null); - __decorate([ - configurable(false), - __metadata("design:type", Object), - __metadata("design:paramtypes", []) - ], Point.prototype, "y", null); - return Point; -}()); -function configurable(value) { - return function (target, propertyKey, descriptor) { - descriptor.configurable = value; - }; -} diff --git a/dist/metadata.js b/dist/metadata.js deleted file mode 100644 index 593f113..0000000 --- a/dist/metadata.js +++ /dev/null @@ -1,56 +0,0 @@ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -var __metadata = (this && this.__metadata) || function (k, v) { - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -require("reflect-metadata"); -var Point = /** @class */ (function () { - function Point() { - } - return Point; -}()); -var Line = /** @class */ (function () { - function Line() { - } - Object.defineProperty(Line.prototype, "p0", { - get: function () { return this._p0; }, - set: function (value) { this._p0 = value; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Line.prototype, "p1", { - get: function () { return this._p1; }, - set: function (value) { this._p1 = value; }, - enumerable: true, - configurable: true - }); - __decorate([ - validate, - __metadata("design:type", Point), - __metadata("design:paramtypes", [Point]) - ], Line.prototype, "p0", null); - __decorate([ - validate, - __metadata("design:type", Point), - __metadata("design:paramtypes", [Point]) - ], Line.prototype, "p1", null); - return Line; -}()); -function validate(target, propertyKey, descriptor) { - var set = descriptor.set; - descriptor.set = function (value) { - var type = Reflect.getMetadata("design:type", target, propertyKey); - if (!(value instanceof type)) { - throw new TypeError("无效的类型。"); - } - set(value); - }; -} -var l1 = new Line(); -console.log(l1); diff --git a/dist/mixins_example.js b/dist/mixins_example.js deleted file mode 100644 index 1831510..0000000 --- a/dist/mixins_example.js +++ /dev/null @@ -1,47 +0,0 @@ -// 一个名为 Disposable 的混入 -var Disposable = /** @class */ (function () { - function Disposable() { - } - Disposable.prototype.dispose = function () { - this.isDisposable = true; - }; - return Disposable; -}()); -// 一个名为 Activatable 的混入 -var Activatable = /** @class */ (function () { - function Activatable() { - } - Activatable.prototype.activate = function () { - this.isActive = true; - }; - Activatable.prototype.deactivate = function () { - this.isActive = false; - }; - return Activatable; -}()); -var SmartObject = /** @class */ (function () { - function SmartObject() { - var _this = this; - // Disposable - this.isDisposable = false; - // Activatable - this.isActive = false; - setInterval(function () { - console.log(_this.isActive + " : " + _this.isDisposable); - }, 500); - } - SmartObject.prototype.interact = function () { - this.activate(); - }; - return SmartObject; -}()); -applyMixins(SmartObject, [Disposable, Activatable]); -var smartObj = new SmartObject(); -setTimeout(function () { return smartObj.interact(); }, 1000); -function applyMixins(derivedCtor, baseCtors) { - baseCtors.forEach(function (baseCtor) { - Object.getOwnPropertyNames(baseCtor.prototype).forEach(function (name) { - derivedCtor.prototype[name] = baseCtor.prototype[name]; - }); - }); -} diff --git a/dist/parameter_decorators.js b/dist/parameter_decorators.js deleted file mode 100644 index 97fa868..0000000 --- a/dist/parameter_decorators.js +++ /dev/null @@ -1,54 +0,0 @@ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -var __metadata = (this && this.__metadata) || function (k, v) { - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); -}; -var __param = (this && this.__param) || function (paramIndex, decorator) { - return function (target, key) { decorator(target, key, paramIndex); } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -require("reflect-metadata"); -var Greeter = /** @class */ (function () { - function Greeter(message) { - this.greeting = message; - } - Greeter.prototype.greet = function (name) { - return "Hello " + name + ", " + this.greeting; - }; - __decorate([ - validate, - __param(0, required), - __metadata("design:type", Function), - __metadata("design:paramtypes", [String]), - __metadata("design:returntype", void 0) - ], Greeter.prototype, "greet", null); - return Greeter; -}()); -var requiredMetadataKey; -function required(target, propertyKey, parameterIndex) { - var existingRequiredParameters = Reflect.getOwnMetadata(requiredMetadataKey, target, propertyKey) || []; - existingRequiredParameters.push(parameterIndex); - Reflect.defineMetadata(requiredMetadataKey, existingRequiredParameters, target, propertyKey); -} -function validate(target, propertyName, descriptor) { - var method = descriptor.value; - descriptor.value = function () { - var requiredParameters = Reflect.getOwnMetadata(requiredMetadataKey, target, propertyName); - if (requiredParameters) { - for (var _i = 0, requiredParameters_1 = requiredParameters; _i < requiredParameters_1.length; _i++) { - var parameterIndex = requiredParameters_1[_i]; - if (parameterIndex >= arguments.length || arguments[parameterIndex] === undefined) { - throw new Error("缺少需要的参数。"); - } - } - } - return method.apply(this, arguments); - }; -} -var g = new Greeter("早上好"); -console.log(g.greet("Echo Feng")); diff --git a/dist/property_decorators.js b/dist/property_decorators.js deleted file mode 100644 index eff2f32..0000000 --- a/dist/property_decorators.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -var __metadata = (this && this.__metadata) || function (k, v) { - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -require("reflect-metadata"); -// 属性装饰器,property decorator -var Greeter = /** @class */ (function () { - function Greeter(message) { - this.greeting = message; - } - Greeter.prototype.greet = function () { - var formatString = getFormat(this, "greeting"); - return formatString.replace("%s", this.greeting); - }; - __decorate([ - format("Hello, %s"), - __metadata("design:type", String) - ], Greeter.prototype, "greeting", void 0); - return Greeter; -}()); -var formatMetadataKey; -function format(formatString) { - return Reflect.metadata(formatMetadataKey, formatString); -} -function getFormat(target, propertyKey) { - return Reflect.getMetadata(formatMetadataKey, target, propertyKey); -} -var g = new Greeter("彭海林"); -console.log(g.greet()); diff --git a/dist/reference.lib.js b/dist/reference.lib.js deleted file mode 100644 index 9b47758..0000000 --- a/dist/reference.lib.js +++ /dev/null @@ -1,2 +0,0 @@ -/// -console.log("foo".padStart(4)); diff --git a/dist/symbol.js b/dist/symbol.js deleted file mode 100644 index 89de993..0000000 --- a/dist/symbol.js +++ /dev/null @@ -1,2 +0,0 @@ -var a; -console.log(a);