2017-12-20 05:33:33 -06:00
|
|
|
import $ from 'jquery';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-11-09 01:37:16 -06:00
|
|
|
import coreModule from './core_module';
|
2016-02-01 16:24:08 -06:00
|
|
|
|
2019-04-28 02:58:12 -05:00
|
|
|
function getBlockNodes(nodes: any[]) {
|
2018-08-30 02:03:11 -05:00
|
|
|
let node = nodes[0];
|
2018-08-29 07:26:50 -05:00
|
|
|
const endNode = nodes[nodes.length - 1];
|
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 05:46:59 -05:00
|
|
|
let blockNodes: any[] | undefined;
|
2018-09-05 03:53:58 -05:00
|
|
|
node = node.nextSibling;
|
2016-02-01 16:24:08 -06:00
|
|
|
|
2018-09-05 03:53:58 -05:00
|
|
|
for (let i = 1; node !== endNode && node; i++) {
|
2016-02-01 16:24:08 -06:00
|
|
|
if (blockNodes || nodes[i] !== node) {
|
|
|
|
if (!blockNodes) {
|
2019-04-28 02:58:12 -05:00
|
|
|
blockNodes = $([].slice.call(nodes, 0, i)) as any;
|
2016-02-01 16:24:08 -06:00
|
|
|
}
|
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 05:46:59 -05:00
|
|
|
|
|
|
|
blockNodes!.push(node);
|
2016-02-01 16:24:08 -06:00
|
|
|
}
|
2018-09-05 03:53:58 -05:00
|
|
|
node = node.nextSibling;
|
2016-02-01 16:24:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return blockNodes || nodes;
|
|
|
|
}
|
|
|
|
|
2018-08-31 09:40:43 -05:00
|
|
|
/** @ngInject */
|
2019-04-28 02:58:12 -05:00
|
|
|
function rebuildOnChange($animate: any) {
|
2016-02-01 16:24:08 -06:00
|
|
|
return {
|
2016-02-02 08:15:20 -06:00
|
|
|
multiElement: true,
|
|
|
|
terminal: true,
|
2016-02-01 16:24:08 -06:00
|
|
|
transclude: true,
|
|
|
|
priority: 600,
|
2017-12-20 05:33:33 -06:00
|
|
|
restrict: 'E',
|
2019-04-28 02:58:12 -05:00
|
|
|
link: (scope: any, elem: any, attrs: any, ctrl: any, transclude: any) => {
|
|
|
|
let block: any, childScope: any, previousElements: any;
|
2016-02-01 16:24:08 -06:00
|
|
|
|
2016-02-02 08:15:20 -06:00
|
|
|
function cleanUp() {
|
2016-02-02 09:32:36 -06:00
|
|
|
if (previousElements) {
|
|
|
|
previousElements.remove();
|
|
|
|
previousElements = null;
|
|
|
|
}
|
2016-02-01 16:24:08 -06:00
|
|
|
if (childScope) {
|
|
|
|
childScope.$destroy();
|
|
|
|
childScope = null;
|
2016-02-02 09:32:36 -06:00
|
|
|
}
|
|
|
|
if (block) {
|
|
|
|
previousElements = getBlockNodes(block.clone);
|
2018-09-04 10:02:32 -05:00
|
|
|
$animate.leave(previousElements).then(() => {
|
2016-02-02 09:32:36 -06:00
|
|
|
previousElements = null;
|
|
|
|
});
|
|
|
|
block = null;
|
2016-02-01 16:24:08 -06:00
|
|
|
}
|
2016-02-02 08:15:20 -06:00
|
|
|
}
|
2016-02-01 16:24:08 -06:00
|
|
|
|
2019-04-28 02:58:12 -05:00
|
|
|
scope.$watch(attrs.property, function rebuildOnChangeAction(value: any, oldValue: any) {
|
2016-02-02 09:32:36 -06:00
|
|
|
if (childScope && value !== oldValue) {
|
2016-02-02 08:15:20 -06:00
|
|
|
cleanUp();
|
2016-02-02 09:32:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!childScope && (value || attrs.showNull)) {
|
2019-04-28 02:58:12 -05:00
|
|
|
transclude((clone: any, newScope: any) => {
|
2016-02-02 08:15:20 -06:00
|
|
|
childScope = newScope;
|
2017-12-21 01:39:31 -06:00
|
|
|
clone[clone.length++] = document.createComment(' end rebuild on change ');
|
2017-12-19 09:06:54 -06:00
|
|
|
block = { clone: clone };
|
2016-02-02 08:15:20 -06:00
|
|
|
$animate.enter(clone, elem.parent(), elem);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
cleanUp();
|
|
|
|
}
|
2016-02-01 16:24:08 -06:00
|
|
|
});
|
2017-12-20 05:33:33 -06:00
|
|
|
},
|
2016-02-01 16:24:08 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.directive('rebuildOnChange', rebuildOnChange);
|