Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
refactor: move custom properties under Lucia namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenybai committed May 6, 2021
1 parent 235f867 commit bd70783
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion scripts/dev.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
esbuild src/browser.ts --bundle --watch --sourcemap --outfile=dist/lucia.dev.js
esbuild src/browser.ts --bundle --watch --sourcemap --global-name=Lucia --outfile=dist/lucia.dev.js
14 changes: 7 additions & 7 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
// Including this file doesn't allow Lucia to be tree shaken, which is
// the main reasoning for omitting this file in CJS and ESM builds

import * as Lucia from './index';
import { init, component } from './index';

if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
// Lucia allows for a custom initialization function
// This is to support for delayed init, like for Turbo Drive

// @ts-expect-error: LuciaInit doesn't exist on window, but we create it.
const init = window.LuciaInit;
// @ts-expect-error: initCallback doesn't exist on window, but we create it.
const initCallback = window.Lucia?.initCallback;

if (init) {
init(Lucia.init);
if (initCallback) {
init(initCallback);
} else {
Lucia.init();
init();
}
});
}

export default Lucia;
export { init, component };
6 changes: 1 addition & 5 deletions src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { directives } from '@core/directive';
import reactive from '@core/reactive';
import render from '@core/render';
import { setElementCustomProp } from '@core/utils/elementCustomProp';
import { ASTNode, DirectiveProps, Directives, State, Watchers } from '@models/structs';
import { ASTNode, Directives, State, Watchers } from '@models/structs';

export class Component {
public state: State;
Expand Down Expand Up @@ -43,10 +43,6 @@ export class Component {
return this.state;
}

public directive(name: string, callback: (props: DirectiveProps) => void): void {
this.directives[name.toUpperCase()] = callback;
}

public watch(name: string, callback: () => void): void {
this.watchers[name] = callback;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { showDirective } from '@directives/show';
import { textDirective } from '@directives/text';

// @ts-expect-error: LuciaDirectives doesn't exist on window, but we create it.
const customGlobalDirectives = window.LuciaDirectives || {};
const customGlobalDirectives = window.Lucia?.directives || {};

export const directives: Directives = {
BIND: bindDirective,
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/computeExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const computeExpression = (
): ((state: KV<unknown>, event?: Event) => any) => {
const formattedExpression = `${returnable ? `return ${expression}` : expression}`;
// @ts-expect-error: LuciaDirectives doesn't exist on window, but we create it.
const customGlobalSpecialProperties = window.LuciaSpecialProperties || {};
const customGlobalSpecialProperties = window.Lucia?.specialProperties || {};
const specialPropertiesNames = [
'$state',
'$el',
Expand Down

0 comments on commit bd70783

Please sign in to comment.