@simpreact/simpreact 0.0.0-alpha.1f6ee65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@simpreact/simpreact",
3
+ "version": "0.0.0-alpha.1f6ee65",
4
+ "description": "",
5
+ "homepage": "https://github.com/dPaskhin/simpreact#readme",
6
+ "main": "./core/index.js",
7
+ "module": "./core/index.js",
8
+ "types": "./core/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./core/index.d.ts",
12
+ "import": "./core/index.js"
13
+ },
14
+ "./jsx-runtime": {
15
+ "types": "./jsx-runtime/index.d.ts",
16
+ "import": "./jsx-runtime/index.js"
17
+ },
18
+ "./jsx-dev-runtime": {
19
+ "types": "./jsx-runtime/index.d.ts",
20
+ "import": "./jsx-runtime/index.js"
21
+ },
22
+ "./hooks": {
23
+ "types": "./hooks/index.d.ts",
24
+ "import": "./hooks/index.js"
25
+ },
26
+ "./dom": {
27
+ "types": "./dom/index.d.ts",
28
+ "import": "./dom/index.js"
29
+ },
30
+ "./shared": {
31
+ "types": "./shared/index.d.ts",
32
+ "import": "./shared/index.js"
33
+ }
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/dPaskhin/simpreact/issues"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/dPaskhin/simpreact.git"
41
+ },
42
+ "type": "module",
43
+ "license": "MIT",
44
+ "author": "Dmitrii Paskhin <d.pasxin@gmail.com>"
45
+ }
@@ -0,0 +1,18 @@
1
+ type Subscriber<Event> = (event: Event) => boolean | void;
2
+ export declare class EventBus<Event = void> {
3
+ private _subscribers;
4
+ /**
5
+ * Synchronously invokes subscribers and passes the event.
6
+ *
7
+ * @param event The event to publish.
8
+ */
9
+ publish(event: Event): void;
10
+ /**
11
+ * Adds a subscriber to the event bus. Subscriber would receive all events published via {@link EventBus.publish}.
12
+ *
13
+ * @param subscriber The subscriber callback.
14
+ * @returns The callback that unsubscribes the subscriber from the event bus.
15
+ */
16
+ subscribe(subscriber: Subscriber<Event>): () => void;
17
+ }
18
+ export {};
@@ -0,0 +1,28 @@
1
+ export class EventBus {
2
+ _subscribers = [];
3
+ /**
4
+ * Synchronously invokes subscribers and passes the event.
5
+ *
6
+ * @param event The event to publish.
7
+ */
8
+ publish(event) {
9
+ for (const subscriber of this._subscribers) {
10
+ subscriber(event);
11
+ }
12
+ }
13
+ /**
14
+ * Adds a subscriber to the event bus. Subscriber would receive all events published via {@link EventBus.publish}.
15
+ *
16
+ * @param subscriber The subscriber callback.
17
+ * @returns The callback that unsubscribes the subscriber from the event bus.
18
+ */
19
+ subscribe(subscriber) {
20
+ const subscribers = this._subscribers;
21
+ if (subscribers.indexOf(subscriber) === -1) {
22
+ subscribers.push(subscriber);
23
+ }
24
+ return () => {
25
+ subscribers.splice(subscribers.indexOf(subscriber), 1);
26
+ };
27
+ }
28
+ }
@@ -0,0 +1,4 @@
1
+ export * from './EventBus';
2
+ export * from './lang';
3
+ export * from './types';
4
+ export * from './utils';
@@ -0,0 +1,4 @@
1
+ export * from './EventBus';
2
+ export * from './lang';
3
+ export * from './types';
4
+ export * from './utils';
@@ -0,0 +1,3 @@
1
+ export declare const EMPTY_OBJECT: Readonly<{}>;
2
+ export declare const EMPTY_ARRAY: readonly never[];
3
+ export declare const EMPTY_MAP: Map<any, any>;
package/shared/lang.js ADDED
@@ -0,0 +1,3 @@
1
+ export const EMPTY_OBJECT = Object.freeze({});
2
+ export const EMPTY_ARRAY = Object.freeze([]);
3
+ export const EMPTY_MAP = new Map();
@@ -0,0 +1,8 @@
1
+ export type Nullable<T> = T | null;
2
+ export type Maybe<T> = Nullable<T> | undefined;
3
+ export type Many<T> = T[] | T;
4
+ export type Dict<T = any> = Record<string, T>;
5
+ export type Primitive = string | number | boolean | bigint | undefined | null;
6
+ export interface VoidFunction {
7
+ (): void;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { Primitive } from './types';
2
+ export declare function isPrimitive(value: unknown): value is Primitive;
@@ -0,0 +1,7 @@
1
+ export function isPrimitive(value) {
2
+ return (value == null ||
3
+ typeof value === 'string' ||
4
+ typeof value === 'number' ||
5
+ typeof value === 'bigint' ||
6
+ typeof value === 'boolean');
7
+ }