Comparing version 5.2.1 to 5.3.0-beta.0
@@ -5,2 +5,9 @@ # Changelog | ||
## [5.3.0-beta.0](https://github.com/tannerntannern/ts-mixer/compare/v5.2.1...v5.3.0-beta.0) (2020-05-31) | ||
### Features | ||
* add hasMixin function ([#27](https://github.com/tannerntannern/ts-mixer/issues/27)) ([c8bfc2d](https://github.com/tannerntannern/ts-mixer/commit/c8bfc2d48854808755088332636e8d166007ed9f)) | ||
### [5.2.1](https://github.com/tannerntannern/ts-mixer/compare/v5.2.0...v5.2.1) (2020-05-08) | ||
@@ -7,0 +14,0 @@ |
export { Mixin, mix } from './mixins'; | ||
export { settings } from './settings'; | ||
export { decorate } from './decorator'; | ||
export { hasMixin } from './mixin-tracking'; |
@@ -10,1 +10,3 @@ "use strict"; | ||
exports.decorate = decorator_1.decorate; | ||
var mixin_tracking_1 = require("./mixin-tracking"); | ||
exports.hasMixin = mixin_tracking_1.hasMixin; |
@@ -7,2 +7,3 @@ "use strict"; | ||
const decorator_1 = require("./decorator"); | ||
const mixin_tracking_1 = require("./mixin-tracking"); | ||
function Mixin(...constructors) { | ||
@@ -50,2 +51,3 @@ const prototypes = constructors.map(constructor => constructor.prototype); | ||
} | ||
mixin_tracking_1.registerMixins(DecoratedMixedClass, constructors); | ||
return DecoratedMixedClass; | ||
@@ -52,0 +54,0 @@ } |
{ | ||
"name": "ts-mixer", | ||
"version": "5.2.1", | ||
"version": "5.3.0-beta.0", | ||
"description": "A very small TypeScript library that provides tolerable Mixin functionality.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -18,2 +18,3 @@ # ts-mixer | ||
* mixes classes that extend other classes | ||
* mixes classes that were mixed with `ts-mixer` | ||
* supports static properties | ||
@@ -23,4 +24,5 @@ * supports protected/private properties (the popular function-that-returns-a-class solution does not) | ||
* mixes generic classes (with caveats [[2](#caveats)]) | ||
* supports class, method, and property decorators (with caveats [[3](#caveats)]) | ||
* supports class, method, and property decorators (with caveats [[3, 6](#caveats)]) | ||
* mostly supports the complexity presented by constructor functions (with caveats [[4](#caveats)]) | ||
* comes with an `instanceof`-like replacement (with caveats [[5, 6](#caveats)]) | ||
* [multiple mixing strategies](#settings) (ES6 proxies vs hard copy) | ||
@@ -33,6 +35,5 @@ | ||
4. ES6 made it impossible to use `.apply(...)` on class constructors (or any means of calling them without `new`), which makes it impossible for `ts-mixer` to pass the proper `this` to your constructors. This may or may not be an issue for your code, but there are options to work around it. See [dealing with constructors](#dealing-with-constructors) below. | ||
5. `ts-mixer` does not support `instanceof` for mixins, but it does offer a replacement. See the [hasMixin function](#hasmixin) for more details. | ||
6. Certain features (specifically, `@dectorator` and `hasMixin`) make use of ES6 `Map`s, which means you must either use ES6+ or polyfill `Map` to use them. If you don't need these features, you should be fine without. | ||
### Non-features | ||
* `instanceof` support. Difficult to implement, and not hard to work around (if even needed at all). | ||
## Quick Start | ||
@@ -219,2 +220,40 @@ ### Installation | ||
## Other Features | ||
### hasMixin | ||
As mentioned above, `ts-mixer` does not support `instanceof` for mixins. While it is possible to implement [custom `instanceof` behavior](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance), this library does not do so because it would require modifying the source classes, which is deliberately avoided. | ||
You can fill this missing functionality with `hasMixin(instance, mixinClass)` instead. See the below example: | ||
```typescript | ||
import { Mixin, hasMixin } from 'ts-mixer'; | ||
class Foo {} | ||
class Bar {} | ||
class FooBar extends Mixin(Foo, Bar) {} | ||
const instance = new FooBar(); | ||
// doesn't work with instanceof... | ||
console.log(instance instanceof FooBar) // true | ||
console.log(instance instanceof Foo) // false | ||
console.log(instance instanceof Bar) // false | ||
// but everything works nicely with hasMixin! | ||
console.log(hasMixin(instance, FooBar)) // true | ||
console.log(hasMixin(instance, Foo)) // true | ||
console.log(hasMixin(instance, Bar)) // true | ||
``` | ||
`hasMixin(instance, mixinClass)` will work anywhere that `instance instanceof mixinClass` works. Additionally, like `instanceof`, you get the same [type narrowing benefits](https://www.typescriptlang.org/docs/handbook/advanced-types.html#instanceof-type-guards): | ||
```typescript | ||
if (hasMixin(instance, Foo)) { | ||
// inferred type of instance is "Foo" | ||
} | ||
if (hasMixin(instance, Bar)) { | ||
// inferred type of instance of "Bar" | ||
} | ||
``` | ||
## Settings | ||
@@ -221,0 +260,0 @@ ts-mixer has multiple strategies for mixing classes which can be configured by modifying `settings` from ts-mixer. For example: |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
43209
20
448
289
1