Coder Social home page Coder Social logo

snowmantw / fluorine Goto Github PK

View Code? Open in Web Editor NEW
40.0 40.0 1.0 1.8 MB

Context-based Javascript eDSL and library; provides a way to isolate impure computations.

Home Page: http://snowmantw.github.com/Fluorine/document/introduce/index.html

JavaScript 63.66% CSS 36.34%

fluorine's People

Contributors

snowmantw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mkfsn

fluorine's Issues

jQuery 'end' need special delegating.

This related to those jQuery context functions. To fix this:

  1. 'find' must record the previous DOM
  2. 'end' will pass the DOM as result.

But this will introduce special states in our own context, so maybe 'end' should not be implemented. In detail:

The 'find' function OK because it use only previous result to execute.
But 'end', in other hand, need previous steps carry on "previous DOMs" as states.

Decorate existing functions to provide debugging tag

Even after a context function had been defined, we're still able to wrap it in some other scripts like this:

// ... some other necessary code ...
var existing = UI.o.protype.$
IO.o.prototype.get = function()
{
    // should handle and save these calls' arguments
    UI.o.prototype.get.__calls_args.push(arguments)

    // calls is lot enough, but I'm not sure if this condition can be made easily
    if( enough() )    
    {
        handlePreviousArguments()     // may use passed in arguments here
        return existing.apply(this, arguments)    // call the wrapped function
    }
    return UI.o.prototype.$  // return self to accept more calls if not enough
}

This trick is ugly and may be not easy to implement well, but if we handle it well, we can provide users such feature:

IO("/resource/manifest.json")(TAG)
    .get( )(TAG)(BREAK)
    .done()

These functions can come with optional calls to behavior differently.Although I feel it's will be much easier to create new chaining function to "decorate" other functions:

IO("/resource/manifest.json")(TAG)
    .get( ).tag(TAG).break(BREAK)
    .done()

In current stage the later way seems more proper to implement the debug feature.

Event's bind function won't execute inner context more than once.

Happens when: Event bind ( UI ) context, and the context won't execute more than once while the notification be exactly triggered twice.

Bind function need to be fixed. I may refactor it and make it more robust under different circumstances.

Workaround: Discard pureness issues and use '_' lambda function instead.

Debug message should come with correct function name for extending contexts

Every function in contexts optionally has its own name, and it will be printed in debug mode. But if we extend a new context from the existing one, those functions not be extended will use the name given in the basic context when we called them. For example:

IO.get          --> New function come without any problem
IO.initialize() --> Not extended; will call Context.initialize()
IO.run( )       --> Extended; will display its name

If we create a chain like this and execute it:

IO("/resource/manifest.json").get( ).done( )( )

The debug messages will be like:

[DEBUG] Process executing step #0, step name(if any): Context::initialize ( call with ), [] 
[DEBUG] Process executing step #1, step name(if any): IO::run ( call with ), ["/resource/manifest.json"]
// ....

The #0 step, which actually calls the Context::initialize, should be corrected with IO::initialize, which is more useful for debugging.

Can't embedded Event context in another Event ( abnormal behavior ).

Happens when: Event context bind another Event context.
Behavior: The inner context won't wait for notification triggering, but execute itself immediately.
Caused by: The base context seems embed the inner context's steps without consider possible problems.

This should be a arguable feature, and won't be fixed before next version.

Single chain should be allowed wrapped by idGen

Add a done() like function to let user can directly turn the chain into wrapped one.

From this:

idGen(  UI('body').$().text("Hello").done()()  )

to this:

UI('body').$().text("Hello").idGen()

Users can get rid of troubles caused by the parenthesis, especially the chain become longer and complex.

Implement the simple type checking rules

At this moment introducing complete but complex type checking rules isn't proper. We should implement a simple enough but useful type checking mechanism to prevent some obvious but hardly to discover errors, like asking for Context but receiving a function.

The main idea is to avoid to distinguish inherited objects like UI vs. IO, and check only primitive types like Function vs. Object, or "our primitive types" like Context vs. UI (different level).

This feature can be tough work, but it can show how important our "definition" stages are.

Event binding on DOM and the whole page

If DOM elements come with '[data-fluorine-events="dom-event-id:click,hover"]',
it should be automatically bound to forward events: 'dom-event-id-click' and 'dom-event-id-hover' after call a fluorine function: fluorine.bindEvents

Another similar method should be in the UI context, which own type:

DOM -> UI DOM

and will accept a DOM to do the same thing. It should be named as 'autobind'.

Add `debug` function in basic context to allow user print debugging message

We can achieve the same goal with anonymous function combinator:

IO('/resources/manifest.json')
    ._( function(){ console.log('URL') } )
    .get()
    ._( function(){ console.log('get') } )
    .done()()

This allow user to monitor steps of the chain while execute it. But it's very annoying to repeat the function(){ console.log ... everywhere. We can provide a debug, or more general, a log function to output these messages.

Add a polling method in the IO

For those polling required method, we should add a polling method like this:

IO().polling('/wait_something', 400, 3, check).done()

It means polling the server with endpoint '/wait_something' every 400ms, and automatically turns failed if it didn't get right answer, which is neither caused by errors (handle by the method implicitly) nor fails to pass the check more than 3 times.

Behavior are different between anonymous generator and idgen

Usually we use idgen() function to avoid redundant anonymous generator:

s1 = UI( ).idge( )

Is equal to:

s2 = function( ) { return UI( ).idgen( ) }

But they're actually different while used in Event context, and will cause the ting failed. In other words, this will work:

g = Event('foo').tie(s2).done( )
g( )
Notifier.trigger('foo')

But this will not:

g = Event('foo').tie(s1).done( )
g( )
Notifier.trigger('foo')

The last one g will report "Tying an undone context or just not a context.", and leave a none executed step in the process stack. Thus next time when the notification get triggered again, the event will execute only one step then (implicitly) refresh the whole process.

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.