Frontend mvp#3
Conversation
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>mlut playground</title> | ||
| <link rel="stylesheet" href="/src/assets/style/style.css" /> | ||
| <script type="module" src="/src/components/code-editor.js"></script> |
There was a problem hiding this comment.
Все скрипты должны быть не в head а в концу body
| </button> | ||
| </div> | ||
| <!-- HTML part's body--> | ||
| <div class="H-calc(100%;-;var(--ml-sectionHeaderH)) Bgc-$core700"> |
There was a problem hiding this comment.
Попробуй здесь обычный синтаксис для кастомных свойств через $
| "thememirror": "^2.0.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@codemirror/lang-html": "^6.4.11", |
There was a problem hiding this comment.
Это не dev зависимость. Хотя если vite в бандл все собирает, то можно и все в dev
There was a problem hiding this comment.
Случайно по инерции в dev-зависимости записал :)
| @@ -0,0 +1,189 @@ | |||
| import {signal} from "@lit-labs/signals" | |||
|
|
|||
| const layout = signal( ` | |||
There was a problem hiding this comment.
Если это что-то временное, то ок, а иначе выглядит очень странно
There was a problem hiding this comment.
А почему это выглядит странно? Лучше объявление сигналов сделать в отдельном месте, а данные держать отдельно?
| import { LitElement, html } from 'lit'; | ||
| import { watch, SignalWatcher } from '@lit-labs/signals'; | ||
|
|
||
| // General CodeMirror imports |
There was a problem hiding this comment.
Зачем эти комменты - все очевидно же. Максимум, можно пустой строкой отделить
| })) | ||
|
|
||
| export class CodeEditor extends LitElement { | ||
|
|
There was a problem hiding this comment.
Зачем пустая строка в начале класса и некоторых методов?
| export class MainComp extends LitElement { | ||
|
|
||
| createRenderRoot() { | ||
| return this.querySelector('main'); |
| textareas.forEach((el, index) => { | ||
| if (el.id === `${this.radioId.toLowerCase()}-area`) { | ||
| displayEditor() { | ||
| const editors = document.querySelectorAll('div[data-type="style"]'); |
There was a problem hiding this comment.
Здесь что-то странное происходит. Этот компонент не должен явно доставать другие
0ae5501 to
0929e77
Compare
| @@ -0,0 +1,52 @@ | |||
| const initialLayout = ` | |||
There was a problem hiding this comment.
| const initialLayout = ` | |
| export const initialLayout = ` |
| @@ -0,0 +1,26 @@ | |||
| export class EventBus { | |||
There was a problem hiding this comment.
Зачем писать свой с багами, если можно взять готовую либу? Вот эту например, 108 байт весит
| <script type="importmap"> | ||
| { | ||
| "imports": { | ||
| "@mlut/core": "../packages/core/dist/index.js", |
| } | ||
| </script> | ||
| <script type="module"> | ||
| const contentLoader = document.querySelector('.loader'); |
There was a problem hiding this comment.
Зачем это отдельным скриптом, да еще и в теге?
| ` | ||
| const initialConfig = ` | ||
| @use "@mlut/core/tools"; | ||
| @use "@mlut/core/dist/sass/css/styles"; |
There was a problem hiding this comment.
Зачем здесь это? Достаточно @mlut/core импортировать
| } | ||
| } | ||
| ` | ||
| const loaderStyles = ` |
| this.view = new EditorView(this.setEditorOptions(this.lang)); | ||
|
|
||
| if (this.lang === 'css') { | ||
| this._eventBus.value.on('update-css', this.updateCss); |
There was a problem hiding this comment.
Зачем каждый раз писать _eventBus.value если можно сразу в свойство записать это value?
| this.timeoutID = setTimeout(() => { | ||
|
|
||
| if (this.lang === 'html') { | ||
| this._eventBus.value.emit('update-html', { |
There was a problem hiding this comment.
Зачем здесь дублирование кода, если можно было использовать один код с 'update-${this.lang}l'?
|
|
||
| static properties = { | ||
| lang: { type: String }, | ||
| timeoutID: { type: Number, state: false }, |
There was a problem hiding this comment.
По названию непонятно, что за timeoutID
| this._eventBus.value.on('update-sass', this.handleUpdate); | ||
| const { jitEngine } = await import('https://unpkg.com/@mlut/core@latest/dist/index.js'); | ||
| await jitEngine.init(['config.scss', initialConfig]); | ||
| jitEngine.putContent('index.html', initialLayout); |
There was a problem hiding this comment.
Зачем здесь отдельно делается putContent, если есть функция для обновления? Тут только инициализация должна быть. Еще и разный путь (название) до файлов
| async firstUpdated() { | ||
| this._eventBus.value.on('update-html', this.handleUpdate); | ||
| this._eventBus.value.on('update-sass', this.handleUpdate); | ||
| const { jitEngine } = await import('https://unpkg.com/@mlut/core@latest/dist/index.js'); |
There was a problem hiding this comment.
Почему динамический, а не обычный импорт?
| @@ -0,0 +1,16 @@ | |||
| import { LitElement, html } from 'lit'; | |||
|
|
|||
| export class ContentLoader extends LitElement { | |||
There was a problem hiding this comment.
Зачем отдельный компонент для лоадера? Недостаточно 1 css класса?
| @@ -0,0 +1,23 @@ | |||
| import { LitElement, html } from 'lit'; | |||
|
|
|||
| export class ErrorFallback extends LitElement { | |||
There was a problem hiding this comment.
Зачем этот компонент? Надо просто 1 абзац стилизованного текста показать, если ошибка
|
|
||
| import { EventBus } from '../assets/scripts/event-bus.js'; | ||
|
|
||
| export const eventBusContext = createContext('eventBus'); |
There was a problem hiding this comment.
Контекст должен в отдельном модуле объявляться. В доке же есть пример
|
|
||
| constructor() { | ||
| super(); | ||
| this.cssChecked = 'unchecked'; |
There was a problem hiding this comment.
Почему такое странное переключение состояния?
|
|
||
| render() { | ||
| return html` | ||
| <div id="${this.lang}-editor" class="H100p Bgc-$core700 Ov-a" style="height: ${this.inProgress ? '0' : '100%'}"> |
| } | ||
|
|
||
| return html` | ||
| <iframe srcdoc='<!DOCTYPE html> |
There was a problem hiding this comment.
Тут что-то странное делается. По идее, надо отправлять в iframe по api. Либо попробуй shadow dom, чтобы такое же простое обновление сохранить
d8f1199 to
df774bb
Compare
df774bb to
0b43148
Compare
No description provided.