Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renderHandler option that will allow to echo different types of data in one place #526

Closed
2 tasks done
jcubic opened this issue Sep 11, 2019 · 4 comments
Closed
2 tasks done
Labels
feature resolved if issue is resolved, it will be open until merge with master

Comments

@jcubic
Copy link
Owner

jcubic commented Sep 11, 2019

I have idea for a new feature for jQuery Terminal

Global echoHandler or renderHandler:

term.echo({xx:10});

this will render [Object object]

I'm thinking about:

renderHandler: function(obj) {
  if (typeof obj !== 'string' && obj !(instanceof Array)) {
      if (obj !== null && typeof obj === 'object') {
         this.echo('[[;;;json]x]', {
             finalize: function(div) {
                 var node = div.find('.json');
                 var new_div = $('<div/>').renderJSON(obj);
                 node.replaceWith(new_div);
             }
         });
      }
      return false;
  }
}

and this can render any object that is passed to echo, as with this Demo: https://codepen.io/jcubic/pen/yLBjJRp?editors=0110

this will be really powerfull because you will be able to render for instance JSX code after transpilation, Maybe this can be simplified to have render method that will allow to use syntax like this:

this.render(function(div) {
});

and render will just do:

render: function(fn) {
    this.echo('', {
        finalize: function(div) {
            fn.call(this, div.empty()));
        }
    });
}

TODO:

  • Create POC of rendering React App inside terminal echo
  • Figure out to not re render on each resize
@jcubic jcubic added the feature label Sep 11, 2019
@jcubic
Copy link
Owner Author

jcubic commented Sep 11, 2019

Maybe destroy option to echo, will be also good idea. I should rethink this Demo:
Vintage Terminal on Codepen it most likely create memory leaks because when you call clear it don't revoke the URL if used.

@jcubic
Copy link
Owner Author

jcubic commented Sep 13, 2019

POC for react inside terminal, with old API, it don't clear on resize.

https://codepen.io/jcubic/pen/ExYRopz?editors=1010

@jcubic
Copy link
Owner Author

jcubic commented Oct 25, 2019

New API will just allow to echo DOM nodes or jQuery objects. Render handler also can return DOM nodes.

@jcubic jcubic added the resolved if issue is resolved, it will be open until merge with master label Oct 25, 2019
@jcubic
Copy link
Owner Author

jcubic commented Oct 25, 2019

Here is CodePen demo that shows, how to echo JSX object directly term.echo(<App/>) with new API.

https://codepen.io/jcubic/pen/XWWRLZo?editors=1011

jcubic added a commit that referenced this issue Oct 25, 2019
jcubic added a commit that referenced this issue Oct 26, 2019
add onClear and unmount methods to echo
add this context to finalize
pass options to render method so echo with with DOM nodes and jQuery object
Update TypeScript definition
@jcubic jcubic closed this as completed Nov 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature resolved if issue is resolved, it will be open until merge with master
Projects
None yet
Development

No branches or pull requests

1 participant