Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Machy8 committed Nov 27, 2023
1 parent c716dc1 commit 46843d4
Show file tree
Hide file tree
Showing 18 changed files with 278 additions and 354 deletions.
23 changes: 17 additions & 6 deletions first.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">

<head snippet="head">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand All @@ -10,30 +10,41 @@
<script type="module" src="http://localhost:5173/@vite/client"></script>
</head>

<body snippet="body">
<body>
<style>
[cloak] {
visibility: hidden;
}
</style>

<a href="/second.html">Second</a>

<script type="module">
import Signalize from 'signalizejs';
import fetch from 'signalizejs/fetch';
import snippets from 'signalizejs/snippets';
import directives from 'signalizejs/directives';
import spa from 'signalizejs/spa';

new Signalize({
const { scope } = new Signalize({
plugins: [
fetch(),
snippets(),
spa()
spa(),
directives()
]
});

scope('test', ({ data }) => {
data.click = () => alert('meh');
});
</script>

<div snippet="body">
<a href="/second.html">Second</a>
<div scope="test">
<button @click="click()">Click</button>
</div>
</div>

</body>

</html>
58 changes: 15 additions & 43 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,49 +38,21 @@
});
</script> -->

<input id="title-input" placeholder="Add Title">
<input id="content-input" placeholder="Add Content">

<div id="output"></div>

<script type="module">
import Signalize from 'signalizejs';

const { Signal, bind } = new Signalize();

// 1. Create article signal
const article = new Signal({
title: 'Hello World!',
content: 'Lorem Ipsum'
});

// 2. Bind article signal to title input
bind(document.querySelector('#title-input'), {
// 2.1 Watch article signal
value: [article, {
// 2.2 Setter for title proerty
set: (title) => article.set({ ...article(), title }),
// 2.3 Getter for title property
get: () => article().title
}]
});

// 3. Bind article signal to content input
bind(document.querySelector('#content-input'), {
// 3.1 Watch article signal
value: [article, {
// 3.2 Setter for content property
set: (content) => article.set({ ...article(), content }),
// 3.3 Getter for content property
get: () => article().content
}]
});

// 4. Bind output
bind(document.querySelector('#output'), {
html: [article, () => `Title: ${article().title}<br>Description: ${article().content}` ]
});
</script>
<script type="module">
import Signalize from 'signalizejs';
// Import directives core
import directives from 'signalizejs/directives';
// Import only those directives, you use
import forDirective from 'signalizejs/directives/for';

// Use the directives plugin
new Signalize({
plugins: [
directives(),
forDirective()
]
})
</script>

<!-- <div $count="1">
<template :for="i of 1">
Expand Down
15 changes: 0 additions & 15 deletions packages/signalizejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@
"require": "./dist/plugins/directives.cjs",
"types": "./dist/plugins/directives.d.ts"
},
"./directives/bind": {
"import": "./dist/plugins/directives/bind.js",
"require": "./dist/plugins/directives/bind.cjs",
"types": "./dist/plugins/directives/bind.d.ts"
},
"./directives/for": {
"import": "./dist/plugins/directives/for.js",
"require": "./dist/plugins/directives/for.cjs",
Expand All @@ -63,16 +58,6 @@
"require": "./dist/plugins/directives/if.cjs",
"types": "./dist/plugins/directives/if.d.ts"
},
"./directives/on": {
"import": "./dist/plugins/directives/on.js",
"require": "./dist/plugins/directives/on.cjs",
"types": "./dist/plugins/directives/on.d.ts"
},
"./directives/signal": {
"import": "./dist/plugins/directives/signal.js",
"require": "./dist/plugins/directives/signal.cjs",
"types": "./dist/plugins/directives/signal.d.ts"
},
"./h": {
"import": "./dist/plugins/h.js",
"require": "./dist/plugins/h.cjs",
Expand Down
59 changes: 55 additions & 4 deletions packages/signalizejs/src/Signalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,58 @@ export class Signalize {
#plugins = new Set();

constructor (options: Partial<SignalizeOptions> = {}) {
this.#init(options);
this.root = options?.root ?? document;
const readyListeners: CallableFunction[] = [];
let inited = false;

const usePlugins = (signalizeInstance: Signalize, plugins: SignalizePlugin[]) => {
for (const plugin of plugins) {
signalizeInstance.use(plugin);
}
}

if (this.root?.__signalize === undefined) {
this.attributePrefix = options?.attributePrefix ?? '';
this.attributeSeparator = options?.attributeSeparator ?? '-';
this.globals = { ...this.globals, ...options?.globals ?? {} };
task(this);
dispatch(this);
on(this);
this.customEventListener('signalize:ready', ({ listener }) => {
if (inited) {
listener(this);
return;
}
readyListeners.push(listener);
});
off(this);
domReady(this);
select(this);
traverseDom(this);
scope(this);
signal(this);
bind(this);
mutationsObserver(this);

usePlugins(this, options?.plugins ?? []);

while (readyListeners.length > 0) {
readyListeners.shift()();
}

this.on('dom:ready', () => {
this.observeMutations(this.root);
});

this.root.__signalize = this;
inited = true;
}

const signalizeInstance = this.root.__signalize;
signalizeInstance.globals = { ...signalizeInstance.globals, ...options?.globals ?? {} };

usePlugins(signalizeInstance, options?.plugins ?? []);

return this.root.__signalize;
}

Expand All @@ -66,10 +117,10 @@ export class Signalize {
}

readonly #init = (options: Partial<SignalizeOptions>): void => {
this.root = options?.root ?? document;
/* this.root = options?.root ?? document;
if (this.root?.__signalize !== undefined) {
throw new Error('Signalize already initialized for the root');
return;
}
this.attributePrefix = options?.attributePrefix ?? '';
Expand Down Expand Up @@ -104,7 +155,7 @@ export class Signalize {
this.observeMutations(this.root);
});
this.root.__signalize = this;
this.root.__signalize = this; */
}
}

Expand Down
45 changes: 0 additions & 45 deletions packages/signalizejs/src/plugins/asset-loader.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/signalizejs/src/plugins/bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export default ($: Signalize): void => {

let getListener: CallableFunction | null = null;
let setListener: CallableFunction | null = null;

if (attributeBinderIsSignal) {
getListener = () => attributeBinder();
setListener = (value) => attributeBinder.set(value);
Expand Down
Loading

0 comments on commit 46843d4

Please sign in to comment.