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

SnippetBridge, IRenderable & TemplateFactory #157

Open
hrach opened this issue Sep 4, 2016 · 0 comments
Open

SnippetBridge, IRenderable & TemplateFactory #157

hrach opened this issue Sep 4, 2016 · 0 comments

Comments

@hrach
Copy link
Contributor

hrach commented Sep 4, 2016

Current bridge layer & framework itself is not easily extensible via implementing interface. Nette Application itself defines few interfaces, but their design, naming and usage inside the framework is not good.

  1. SnippetBrige contains non-trivial logic, which shouln't be probably in "bridge". Morover, it somehow works with component tree model & IRenderable, but accepts only Control.

  2. IRenderable - somehow it says from its name, that it decides if something will be renderer. However, in the code, isControlInvalid() is used only in AJAX mode, moreover, the second methods is used only with snippets, which makes maily (but not exlusively) sence with snippets names, which are in fact not defined in interface!!! and are marked as optional arguments in control.

  3. Bridge - TemplateFactory also sctrictly accept only Control or null, though, almost no functionality in the factory depends (directly) on it.


Possible solution:

  1. Decouple UI control & link creation. (eg. macro {link} won't be call on object of UIControl.) This should be handled in a different way. I can imagine that some tree structure should be injected into template, and link macro will reuse it, but it should be done in different time and place.

  2. Possible rename IRenderable to IControl, add proper methods for snippets functionality and proper method naming (isInvalidControl vs redrawControl). Eg.

interface IControl
{
public function shouldRedraw(?string $snippet = null);
public function redrawControl(?string $snippet = null, bool $redraw = true);
}
  1. Store snippetMode in snippetBridge, or just outside the Control. If the whole logic is in SnippetBridge::renderChildren(), there is no need to have it in Control.

  2. Rename SnippetBridge::renderChildren() to SnippetBrige::render(). There is no need that SnippetBrige should now about some tree structure, it has nothing to do with snippets.

  3. Move the tree traversal logic of isInvalidControl outside the Control. The logic is currently copy-pasted in SnippetBridge::renderChildren() and could be probably somehow unified in this bridge, or better, extracted to some helper hlass which will do the traversion for IComponent & IContainer.

  4. Basically, let all parts of SnippetBrige, TemplateFactory etc. work with IControl.


It's just a quick bugreport (which took several about hour to write and some others to go through the code), maybe there are some better solutions, the general, or just for some mentioned poits.

I believe it's possible to do it with minimum BC breaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant