hiun / refinable Goto Github PK
View Code? Open in Web Editor NEWRefinable Functions Constructor for Aspect and Feature Modularity
Home Page: https://hiun.org/refinable
License: MIT License
Refinable Functions Constructor for Aspect and Feature Modularity
Home Page: https://hiun.org/refinable
License: MIT License
consider .catch
for this.
behavior(1).exec(hdr).catch(errHdr)
their occupations are frozen. do not edited.
as follows the design goal, these identical behaviors must updates by any matched operations such as assign
and update
.
some methods(_args
) is exposed to public, consider update to private
var decorator = funcA.asAround();
var decorated function = decorator.compose(Function/Refinable);
is it useful?
Functions in JavaScript is flexible, indeed it does not enforce parameter and return type.
In order to ensure correctness of program, typechecking for function refinement is needed.
The rule for checking type validity for function refinement is simple, output(return) type of function must be covariant(subtyped) for input(parameter) of succeeding function. In other words, input(parameter) of function should be contravariant for its argument(returned data from preceding function)
Below table shows list of supported types
Name | Notation |
---|---|
Boolean Type | boolean |
Number Type | number |
String Type | string |
Array Type | array |
Any Type | any |
Null Type | null |
Undefined Type | undefined |
Intersection Type (traits) | Object.assign(typeA, typeB) |
Union Type (priority type) | typeA|typeB|typeC |
Optional Type | ?typeA |
assign(Object<Function|Self>): this
catch(Function|Self): this
defineMethod(String, Function|Self): this
allow internal method to receive refinable function as primitive executable object that is complementary to the native function
currently only primitive function
I'm considering defineMethod
to achieve it.
Internal implementation would be returning a function that takes array of sub-behaviors which affects custom refinement.
Refinable Functions focuses on function-level refinement, however implicit augmentation of method in classes is essential for implementing aspect-orientation. This idea requires 2 new mechanism of refinement.
Advices is class of function that modifies other function when run. It is a certain function, method or procedure that is to be applied at a given join point of program,(wikipedia). The join point is represented in keyword like before
, after
and around
in typical aspect-orientation, where as point cut represent point of join point composition. I propose following syntax for export Refinable Function as ann Advice
subjectChangeAdvice.export.before('subjectChange');
subjectChangeAdvice.export.after('subjectChange');
subjectChangeAdvice.export.around('subjectChange');
In this sense, function refinement and class refinement is performed in two phase.
Aspect-oriented Programming towards localization of cross-cutting concerns using aspect object that augment a behavior of method. The aspect object itself can be inheritable, for example the following codes is aspect for ObserverProtocol
.
var ObserverProtocolAspect = {
perSubjectObservers: new WeakMap(),
getObservers: function (subject) {
observers = this.perSubjectObservers.get(subject);
if (observers == null) {
perSubjectObservers.put(subject, []);
}
return observers;
},
addObserver: function (subject, observer) {
getObservers(subject).add(observer);
},
removeObserver: function (subject, observer) {
getObservers(subject).remove(observer);
},
//subjectChange: null,
//below method implicies subject change is required field for its subaspect
subjectChange: new Self().add(inputCheck).add(function (subject, observer) {
return this.updateObserver(subject, observer)
}).export.before()
};
var ObserverProtocol = new Self.utils.aspect(ObserverProtocolAspect);
and by extending ObserverProtocol
aspect, we can make more concrete subaspect called ColorObserver
using .extends
method.
//interception instead of composition
var ColorObserver = {
subjectChange: function subjectChange(subjectChange) {
return {
setColor: subjectChange,
setLine: subjectChange
}
},
updateObserver: function (subject, observer) {
//type is needed
//fault of dynamic type checking => static typechecking and aspect weaving make weaving reliable
//type system make aspect weaving safe and deterministic
//
this.display("color updated")
}
}
var ColorObserver = new Self.utils.aspect(ColorObserver);
ColorObserver.extends(ObserverProtocol);
//member variable manipulation, function manipulation
ColorObserver.compose(className);
to follow convention of aop, and the functionality is the same
promise is crucial for async processing. consider supporting promise natively. As a result, we have three types of sub-behavior. Function object, Behavior object and Promise object.
ideas needed
such as repeat
, chaining of these operation to performing high-level refinement.
it is easy to implement repeat
method but we have a major issue. By using repeat
, the element of array will be duplicated.
How can we treat and represent sub-behavior that has same name? Does delete
and assign
operation have to manipulates all sub-behavior under the same name?
length or lists of all sub-behavior by accessed by method or static property.
those property is useful for custom method like defineMethod
.
especially for async/await and proxy
modification using other method or
wrapping function into object is needed (preferred)
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.