html-injector icon indicating copy to clipboard operation
html-injector copied to clipboard

Production ready?

Open shakyShane opened this issue 9 years ago • 4 comments

This is a todo-list for tracking what I consider to be deal-breakers stopping me promoting & classifying this plugin as production ready.

  • [ ] Cannot update both the innerText + attrs on a changed node. For example, often when rendering markdown, if the title inside a h1 changes to Blog post then the id can also change to become <h1 id="blog-post">Blog post</h1>. Solution - Allow multiple tasks to be executed per changed node
  • [ ] Give some indication to the browser that either HTML was injected, or that no match was found for the current restrictions. Solution Use Browsersync's .notify() method to give useful info + allow it to be switched off.
  • [ ] Can we also handle auth? Say a user is logged into a browser session, when we request the updated HTML via the request module, how can we replay the original request to also include the cookies to ensure we're getting back what we expect.

shakyShane avatar Aug 02 '15 06:08 shakyShane

I have another point to bring into the discussion: Is this tool supposed to work with single page apps using frameworks like Angular, React, etc? Is this even viable? Let's consider:

With Angular we'll have to somehow force recompilation of directives. It shouldn't be that hard:

// 1. Get all instances of old template in live HTML

var instances = getTheContainerElementsFor(changedHTML);

// 2. Get the $compile service from the current app:

var $compile = angular.element('.ng-scope').injector().get('$compile');

// 3. Replace all instances with new HTML and compile with original scopes

instances.forEach((instance) => {
  var element = angular.element(instance);
  var scope = element.scope();

  $compile(element.replaceWith(changedHTML))(scope);
});

// 4. Wrap up with refreshing the whole up:

$scope.$apply();

stereokai avatar Aug 02 '15 08:08 stereokai

@shakyShane ?

stereokai avatar Aug 04 '15 04:08 stereokai

Wow! if it's really that easy to hot-update angular directives I'd certainly be happy to support this. Would be pretty easy too, although I'm thinking it would be a separate BS plugin.

shakyShane avatar Aug 04 '15 06:08 shakyShane

Any plans to continue development?

ArmorDarks avatar Sep 15 '16 10:09 ArmorDarks