Skip to content

Commit

Permalink
Deprecate Model#log()
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Nov 24, 2024
1 parent 1975281 commit 019d8b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 30 deletions.
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
- Added `context` event to `Model`, with `prevContext` and `nextContext` parameters, triggered when the context changes
- Changed `Model#context` to be an accessor property, where the setter calls `Model#setContext(value, true)`
- Changed `ViewModel#setData()` to no longer accept a `context` argument or change the context
- Changed `ViewModel#setDataProgress()` to no longer change the context, despite accepting `context` argument
- Updated `ViewModel` to trigger a render when the `context` event is fired
- Added the `EmbedApp#publicApi.setLocationSync()` method to simplify sync between the embed app and the host location, preventing potential pitfalls
- Added `ViewModel#enforceScheduledRenders()` to immediately execute scheduled renders
- Changed `ViewModel#scheduleRender()` to use `setTimeout()` instead of `Promise.resolve()` to ensure proper processing of event loop tasks, eliminating unnecessary renders
- Changed `ViewModel` initialization to minimize unnecessary renders
- Marked `ViewModel#renderPage()`, `ViewModel#renderSidebar()`, and `ViewModel#renderPage()` as private methods, as they are not intended for direct invocation.
- Marked `ViewModel#renderPage()`, `ViewModel#renderSidebar()`, and `ViewModel#renderPage()` as private methods, as they are not intended for direct invocation anymore
- Fixed `ViewModel#setPageParams()` to normalize the `hash` by ensuring it starts with `#`, preventing unnecessary events; for example, passing `#page` and `page` into the method will now consistently result in `#page` being stored in `ViewModel#pageHash`
- Redesigned logging API:
- Redesigned logging API, the changes allow to see the correct loaction of logging method call instead of a location inside of the `Model#log()` method:
- Added `Logger` class to utils
- Changed `Model#logger` to hold a `Logger` instance
- Removed `Model#logLevel`, use `Model#logger.logLevel` to get or set value
- Deprecated `Model#log()` method, which do nothing but display warning
- Use `Model#logger[level](...args)` instead of `Model#log('level', ...args)`. This approach allows to see the correct loaction of logging method call instead of a location inside of the `Model#log()` method
- Removed `Model#logLevel`, use `Model#logger.logLevel` for getting or setting the log level
- Deprecated `Model#log()` method, which do nothing but display an error:
- Use `Model#logger[level](...args)` instead of `Model#log('level', ...args)`
- Use `Model#logger[level].group(message, fn | array)` or `Model#logger[level].groupCollapsed(message, fn | array)` instead of `Model#logger({ level, message, collapsed: fn | array })`

## 1.0.0-beta.90 (15-11-2024)
Expand Down
27 changes: 2 additions & 25 deletions src/main/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,31 +233,8 @@ export class Model<
}

// logging
log(levelOrOpts: LogOptions | LogLevel, ...args: unknown[]) {
// console.warn(`${logPrefix} Model#log() is deprecated, use Model#logger interface instead`);
const {
level,
lazy = null,
message = null,
collapsed = null
} = typeof levelOrOpts === 'object' && levelOrOpts !== null ? levelOrOpts : { level: levelOrOpts };

if (this.logger.shouldLogLevel(level)) {
const method = level === 'perf' ? 'log' : level;

if (collapsed) {
console.groupCollapsed(`${logPrefix} ${message ?? args[0]}`);

const entries = typeof collapsed === 'function' ? collapsed() : collapsed;
for (const entry of Array.isArray(entries) ? entries : [entries]) {
console[method](logPrefix, ...Array.isArray(entry) ? entry : [entry]);
}

console.groupEnd();
} else {
console[method](logPrefix, ...typeof lazy === 'function' ? lazy() : args);
}
}
log() {
this.logger.error('Model#log() is deprecated, use Model#logger interface instead');
}

// ==========
Expand Down

0 comments on commit 019d8b8

Please sign in to comment.