Code Monkey home page Code Monkey logo

refinable's People

Contributors

hiun avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

refinable's Issues

proactive function export

var decorator = funcA.asAround();
var decorated function = decorator.compose(Function/Refinable);

is it useful?

proposal for function refinement typechecking

Motivation

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.

Typechecking Rules

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)

Type Lists

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

Examples

user-definable method

I'm considering defineMethod to achieve it.

Internal implementation would be returning a function that takes array of sub-behaviors which affects custom refinement.

proposal for class-level refinement

Motivation

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.

1.Refinable Functions as a Advice

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.

2.Class-level Refinement with Aspect-oriented Programming

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);

promise as a sub-behavior

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.

creating repeat method

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 deleteand assign operation have to manipulates all sub-behavior under the same name?

Get static information of behavior

length or lists of all sub-behavior by accessed by method or static property.
those property is useful for custom method like defineMethod.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.