overlookmotel / class-extension Goto Github PK
View Code? Open in Web Editor NEWClass extensions
License: MIT License
Class extensions
License: MIT License
Presently, you create an extension which extends another extension with:
const myExt = new Extension( {
extend( Class ) {
Class = Class.extend( otherExtension );
Class = Class.extend( anotherExtension );
return class extends Class { /* ... */ };
}
} );
Instead could provide the extensions to the plugin constructor:
const myExt = new Extension( {
extends: [ otherExtension, anotherExtension ],
extend: Class => class extends Class { /* ... */ }
} );
This change would have 2 advantages:
Where an extension extends another extension, and that extension is already applied, it prevents the extension being applied twice.
const M = Main.extend( extensionA )
.extend( extensionB )
.extend( extensionA );
In above case, extensionA
is deduplicated (see docs).
If the two extensionA
s are actually different versions of extensionA
e.g. 1.0.0
and 1.1.0
, an error will be thrown.
It would be better if you could provide an acceptable semver version range which which prevents this error. e.g.:
.extend( extensionA, { version: '^1.0.0' } )
In extensions, ranges could be specified with a dependencies
option:
const otherExt = require('other-ext');
const MyExt = new Extension( {
name: 'my-ext',
version: '0.0.1',
dependencies: {
'other-ext': '^1.0.0'
},
extend( Class ) {
Class = Class.extends( otherExt );
return class extends Class { /* ... */ }
}
} );
Conveniently, if this plugin is in an NPM module, you can then just include package.json
to cover name
, version
and dependencies
in one.
const otherExt = require('other-ext');
const MyExt = new Extension(
require('./package.json'),
( Class ) => {
Class = Class.extends( otherExt );
return class extends Class { /* ... */ }
}
);
There are no tests for this at present.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.