Skip to content

Instantly share code, notes, and snippets.

View arturovt's full-sized avatar
🎯

Artur arturovt

🎯
View GitHub Profile
import { NgModule } from '@angular/core';
import { NgxsModule } from '@ngxs/store';
import { NgxsEmitPluginModule } from '@ngxs-labs/emitter';
@NgModule({
imports: [
NgxsModule.forRoot(states),
NgxsEmitPluginModule.forRoot()
]
})
import { State, StateContext } from '@ngxs/store';
import { Receiver } from '@ngxs-labs/emitter';
export interface CounterStateModel {
value: number;
}
@State<CounterStateModel>({
name: 'counter',
defaults: {
import { Component } from '@angular/core';
import { Select } from '@ngxs/store';
import { Emitter, Emittable } from '@ngxs-labs/emitter';
import { CounterState } from './counter.state';
@Component({
selector: 'app-counter',
template: `
<ng-container *ngIf="counter$ | async as counter">
import('@angular/core');
$ d8 dynamic-import.js --print-bytecode
0 E> 0x1227e79a28aa @ 0 : a2 StackCheck
0 S> 0x1227e79a28ab @ 1 : 12 00 LdaConstant [0]
0x1227e79a28ad @ 3 : 26 f9 Star r2
0x1227e79a28af @ 5 : 27 fe fa Mov <closure>, r1
0x1227e79a28b2 @ 8 : 5e d4 00 fa 02 CallRuntime [DynamicImportCall], r1-r2
0x1227e79a28b7 @ 13 : 26 fb Star r0
25 S> 0x1227e79a28b9 @ 15 : a6 Return
void BytecodeGenerator::VisitImportCallExpression(ImportCallExpression* expr) {
RegisterList args = register_allocator()->NewRegisterList(2);
VisitForRegisterValue(expr->argument(), args[1]);
builder()
->MoveRegister(Register::function_closure(), args[0])
.CallRuntime(Runtime::kDynamicImportCall, args);
}
RUNTIME_FUNCTION(Runtime_DynamicImportCall) {
HandleScope scope(isolate);
DCHECK_EQ(2, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, specifier, 1);
Handle<Script> script(Script::cast(function->shared()->script()), isolate);
while (script->has_eval_from_shared()) {
script = handle(Script::cast(script->eval_from_shared()->script()), isolate);
const cache: {
[key: string]: any;
} = {};
function getModuleCode(path: string): Promise<string> {
return fetch(path).then((res) => res.text());
}
async function import<T = unknown>(path: string): Promise<T> {
if (cache.hasOwnProperty(path)) {
this.currentUrlTree = createEmptyUrlTree();
export function createEmptyUrlTree() {
return new UrlTree(new UrlSegmentGroup([], {}), {}, null);
}