File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
src/Infinityloop/LazyComponent Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types = 1 );
4+
5+ namespace Infinityloop \LazyComponent ;
6+
7+ abstract class LazyComponent extends \Nette \Application \UI \Control
8+ {
9+ private bool $ loaded = false ;
10+
11+ public function handleLoadComponent () : void
12+ {
13+ $ this ->loaded = true ;
14+ $ this ->redrawControl ();
15+ }
16+
17+ public function renderLoadComponentLink () : void
18+ {
19+ echo $ this ->link ('loadComponent ' );
20+ }
21+
22+ public function render () : void
23+ {
24+ if (!$ this ->loaded ) {
25+ $ this ->template ->setFile (__DIR__ . '/emptyComponent.latte ' );
26+ } else {
27+ $ this ->beforeRender ();
28+ $ this ->template ->setFile (\str_replace ('.php ' , '.latte ' , static ::getReflection ()->getFileName ()));
29+ }
30+
31+ $ this ->template ->render ();
32+ }
33+
34+ public function saveState (array &$ params ): void
35+ {
36+ parent ::saveState ($ params );
37+ $ params ['lazyComponent_loaded ' ] = $ this ->loaded ;
38+ }
39+
40+ public function loadState (array $ params ): void
41+ {
42+ parent ::saveState ($ params );
43+ $ this ->loaded = (bool ) ($ params ['lazyComponent_loaded ' ] ?? $ this ->loaded );
44+ }
45+
46+ protected function beforeRender () : void
47+ {
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments