Giter VIP home page Giter VIP logo

nel's People

Contributors

n-riesco avatar thalesmello 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

Watchers

 avatar  avatar

nel's Issues

Compile 2 JavaScript language support

Thank you for your cool things about iPython Notebook.

I just make two line modify to support CoffeeScript. It works!

  function run(code) {
    var compiledCode = require('coffee-script').compile(code, {bare: true})
    if(DEBUG) { console.log("SM: COMPILED: ```\n", compiledCode, '\n') }
    return vm.runInThisContext(compiledCode);
  }

But I'm not familiar with the architecture, I'm thinking how to make it support any compiler that exists(coffeescript, babel, etc...)

Here are some ways to do it:

  1. build-in compiler ijavascript --compile coffee, compiler can provided as plugins(such as ijavascript-coffee-plugin)
  2. I also see a Cell - Cell Type in the dropdown menubar, maybe add some custom cell-type there
Code(javascript)
Code(CoffeeScript)
Code(babel)
Markdown

To implement that, there are some points

  • async compiler support
  • is Cell Type in iPython pluginable?
  • Source Map Support

Enable async execution if result is a Promise

Moved from n-riesco/jp-babel#17

Examples of usage:

  1. When a cell execution returns a promise; e.g.

    getPromise();

    this would be equivalent to

    (function($$) {
        $$.async();
    
        getPromise().then(function(result) {
            $$.sendResult(result);
        }).catch(function(error) {
            $$.sendError(error);
        });
    }($$);
  2. Similarly with other output methods, e.g.:

    $$.html(getPromise());

    this would be equivalent to:

    (function($$) {
        $$.async();
    
        getPromise().then(function(result) {
            $$.html(result);
        }).catch(function(error) {
            $$.sendError(error);
        });
    }($$);

Use `vm.runInContext`

Moved discussion from n-riesco/ijavascript#117 (comment) :


I would solve this issue like this:

  1. replace the following line of code:
ContextifyScript.Script.runInThisContext();

with

ContextifyScript.Script.runInContext(currentContext);
  1. Check for first error

If the code errors out, parse the error to check for this pattern:

SyntaxError: Identifier '*' has already been declared

if this pattern matches, create a new context to be used across the current session, and run the code again, any error created afterwards is propagated to the user.

function createContext() {
  const sandbox = {
    Buffer,
    clearImmediate,
    clearInterval,
    clearTimeout,
    setImmediate,
    setInterval,
    setTimeout,
    console,
    process,
    // ...other ijavascript-y needed context
  };
  sandbox.global = sandbox;
  return sandbox;
}

try {
	ContextifyScript.Script.runInContext(currentContext);
} catch(e) {
   if(DOUBLE_DECL_PATTERN.test(e.message)) {
      currentContext = vm.createContext(createContext());
      return ContextifyScript.Script.runInContext(currentContext);
   }
   throw e
}

I have not looked into the ijavascript code yet, but I am hoping to get some feedback on this before I do so.

[DISCUSS] Implement `display_id` in protocol v5.1

See n-riesco/ijavascript#93 (comment)

@rgbkrk What would be the use case for giving the user access to display_id?

IJavascript handles access to each cell by means of the object $$. Each cell has its own $$. And for this reason, there is no need to know the display_id; we only need to know the $$ of each cell. Here's an example of how to use the $$ of multiple cells:

// In[1]
$$.async();

const $1 = global.$$;
const console1 = global.console;

console1.log("This goes to Out[1]");
$1.text("and this too");

// In[2]
$$.async();

const $2 = global.$$;
const console2 = global.console;

console2.log("This goes to Out[2]");
$2.text("and this too");

// In[3]
console1.log("This goes to Out[1]");
$1.text("and this too");
$1.done(); // close cell 1 output

console2.log("This goes to Out[2]");
$2.text("and this too");
$2.done(); // close cell 2 output

console.log("This goes to Out[3]");
"and this too";

async transpile

In order to ensure functions exist when added as a magic as discussed in n-riesco/ijavascript#43, I need to resolve the function name using the inspect function of the NEL session. Inspect uses callbacks, but transpile is synchronous.

Any objections to wrapping the transpile call in Promise.resolve() to make it indifferent as to whether the transpiler is synchronous or asynchronous? The try / catch could be replaced with .then / .catch to the same effect.

It doesn't look like _runNow expects to be synchronous, so I don't think this would break anything else.

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.