8000 chore: extract reactivity by Shinigami92 · Pull Request #42 · un-ts/unuse · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore: extract reactivity #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


10000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/unuse-reactivity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# unuse-reactivity

`unuse-reactivity` is the reactivity system of `unuse`. It is not provided as a standalone package but compiled into `unuse`'s _dist_ by using `noExternal`.

# UNDER CONSTRUCTION

Right now there is no stable version of `unuse` available. We just working on it.

<img src="https://chronicle-brightspot.s3.amazonaws.com/6a/c4/00e4ab3143f7e0cf4d9fd33aa00b/constructocat2.jpg" width="400px" />
36 changes: 36 additions & 0 deletions packages/unuse-reactivity/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "unuse-reactivity",
"version": "0.2.0",
"description": "learn once, use everywhere",
"scripts": {
"build": "tsdown"
},
"private": true,
"homepage": "https://github.com/un-ts/unuse/tree/main/packages/unuse-reactivity",
"bugs": {
"url": "https://github.com/un-ts/unuse/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/un-ts/unuse.git",
"directory": "packages/unuse-reactivity"
},
"license": "MIT",
"type": "module",
"exports": {
".": "./dist/index.js",
"./package.json": "./package.json"
},
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"dependencies": {
"alien-signals": "^2.0.5"
},
"engines": {
"node": ">=20.11"
}
}
5 changes: 5 additions & 0 deletions packages/unuse-reactivity/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './unComputed';
export * from './unEffect';
export * from './unEffectScope';
export * from './unSignal';
export * from './unWatch';
7 changes: 7 additions & 0 deletions packages/unuse-reactivity/tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'tsdown';

export default defineConfig({
exports: true,
platform: 'neutral',
publint: true,
});
3 changes: 2 additions & 1 deletion packages/unuse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"dist"
],
"dependencies": {
"alien-signals": "^2.0.5"
"alien-signals": "^2.0.5",
"unuse-reactivity": "workspace:*"
},
"devDependencies": {
"@angular/compiler": "20.0.4",
Expand Down
6 changes: 1 addition & 5 deletions packages/unuse/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from 'unuse-reactivity';
export { initFrameworkImport } from './_framework';
export type { SupportedFramework } from './_framework';
export * from './isClient';
Expand All @@ -6,13 +7,8 @@ export * from './toArray';
export * from './toUnSignal';
export * from './tryOnScopeDispose';
export * from './unAccess';
export * from './unComputed';
export * from './unEffect';
export * from './unEffectScope';
export * from './unRefElement';
export * from './unResolve';
export * from './unSignal';
export * from './unWatch';
export * from './useEventListener';
export * from './useIntervalFn';
export * from './useWebSocket';
4 changes: 2 additions & 2 deletions packages/unuse/src/toUnSignal/index.angular.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {
BrowserTestingModule,
platformBrowserTesting,
} from '@angular/platform-browser/testing';
import type { UnSignal } from 'unuse-reactivity';
import { isUnSignal } from 'unuse-reactivity';
import { beforeAll, expect, it, vi } from 'vitest';
import { toUnSignal } from '.';
import { describeAngular, ZonelessTestModule } from '../_testUtils/angular';
import type { UnSignal } from '../unSignal';
import { isUnSignal } from '../unSignal';

describeAngular('toUnSignal', () => {
beforeAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/unuse/src/toUnSignal/index.react.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import { renderHook as renderReactHook } from '@testing-library/react';
import { useState } from 'react';
import { isUnSignal } from 'unuse-reactivity';
import { expect, it } from 'vitest';
import { toUnSignal } from '.';
import { describeReact } from '../_testUtils/react';
import { isUnSignal } from '../unSignal';

describeReact('toUnSignal', () => {
it('should convert a React state to an UnSignal', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/unuse/src/toUnSignal/index.solid.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createSignal } from 'solid-js';
import { isUnSignal } from 'unuse-reactivity';
import { expect, it } from 'vitest';
import { toUnSignal } from '.';
import { describeSolid } from '../_testUtils/solid';
import { isUnSignal } from '../unSignal';

describeSolid('toUnSignal', () => {
it('should convert a Solid signal to an UnSignal', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/unuse/src/toUnSignal/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { unSignal } from 'unuse-reactivity';
import { describe, expect, it } from 'vitest';
import { toUnSignal } from '.';
import { unSignal } from '../unSignal';

describe('toUnSignal', () => {
it('should be defined', () => {
Expand Down
5 changes: 2 additions & 3 deletions packages/unuse/src/toUnSignal/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { Signal as AngularSignal } from '@angular/core';
import type { Accessor as SolidAccessor } from 'solid-js';
import type { UnSignal } from 'unuse-reactivity';
import { isUnSignal, unEffect, unSignal } from 'unuse-reactivity';
import type { Ref as VueRef } from 'vue';
import type { SupportedFramework } from '../_framework';
import { importedFramework } from '../_framework';
import type { MaybeUnRef } from '../unAccess';
import { unEffect } from '../unEffect';
import type { UnSignal } from '../unSignal';
import { isUnSignal, unSignal } from '../unSignal';

const REGISTRY: {
toUnSignalOverride?: typeof toUnSignal;
Expand Down
2 changes: 1 addition & 1 deletion packages/unuse/src/toUnSignal/index.vue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isUnSignal } from 'unuse-reactivity';
import { expect, it } from 'vitest';
import { ref } from 'vue';
import { toUnSignal } from '.';
import { describeVue } from '../_testUtils/vue';
import { isUnSignal } from '../unSignal';

describeVue('toUnSignal', () => {
it('should convert a Vue ref to an UnSignal', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/unuse/src/unAccess/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { unSignal } from 'unuse-reactivity';
import { describe, expect, it } from 'vitest';
import { unAccess } from '.';
import { unSignal } from '../unSignal';

describe('unAccess', () => {
it('should be defined', () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/unuse/src/unAccess/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ import type {
Accessor as SolidAccessor,
Signal as SolidSignal,
} from 'solid-js';
import type { UnComputed, UnSignal } from 'unuse-reactivity';
import { isUnComputed, isUnSignal } from 'unuse-reactivity';
import type { ComputedRef as VueComputedRef, Ref as VueRef } from 'vue';
import type { SupportedFramework } from '../_framework';
import { importedFramework } from '../_framework';
import type { UnComputed } from '../unComputed';
import { isUnComputed } from '../unComputed';
import type { UnSignal } from '../unSignal';
import { isUnSignal } from '../unSignal';

/**
* UnRef represents any kind of reference or signal that can be dereferenced to get its value.
Expand Down
2 changes: 1 addition & 1 deletion packages/unuse/src/unResolve/index.angular.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
BrowserTestingModule,
platformBrowserTesting,
} from '@angular/platform-browser/testing';
import { unSignal } from 'unuse-reactivity';
import { beforeAll, expect, it, vi } from 'vitest';
import { unResolve } from '.';
import { describeAngular, ZonelessTestModule } from '../_testUtils/angular';
import { unSignal } from '../unSignal';

describeAngular('unResolve', () => {
beforeAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/unuse/src/unResolve/index.react.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// @vitest-environment happy-dom

import { renderHook as renderReactHook } from '@testing-library/react';
import { unSignal } from 'unuse-reactivity';
import { expect, it } from 'vitest';
import { unResolve } from '.';
import { describeReact } from '../_testUtils/react';
import { unSignal } from '../unSignal';

describeReact('unResolve', () => {
it('should resolve to a React Ref', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/unuse/src/unResolve/index.solid.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { renderHook as renderSolidHook } from '@solidjs/testing-library';
import { unSignal } from 'unuse-reactivity';
import { expect, it } from 'vitest';
import { unResolve } from '.';
import { describeSolid } from '../_testUtils/solid';
import { unSignal } from '../unSignal';

describeSolid('unResolve', () => {
it('should resolve to an Solid Signal', () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/unuse/src/unResolve/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { isUnComputed, isUnSignal, unSignal } from 'unuse-reactivity';
import { describe, expect, it } from 'vitest';
import { unResolve } from '.';
import { isUnComputed } from '../unComputed';
import { isUnSignal, unSignal } from '../unSignal';

describe('unResolve', () => {
it('should be defined', () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/unuse/src/unResolve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import type {
Accessor as SolidAccessor,
Signal as SolidSignal,
} from 'solid-js';
import type { UnComputed, UnSignal } from 'unuse-reactivity';
import { unComputed, unEffect } from 'unuse-reactivity';
import type { ComputedRef as VueComputedRef, Ref as VueRef } from 'vue';
import type { SupportedFramework } from '../_framework';
import { importedFramework } from '../_framework';
import type { UnComputed } from '../unComputed';
import { unComputed } from '../unComputed';
import { unEffect } from '../unEffect';
import type { UnSignal } from '../unSignal';

export interface UnResolveOptions<
TFramework extends SupportedFramework = typeof globalThis.__UNUSE_FRAMEWORK__,
Expand Down
2 changes: 1 addition & 1 deletion packages/unuse/src/unResolve/index.vue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { unSignal } from 'unuse-reactivity';
import { expect, it } from 'vitest';
import { isRef } from 'vue';
import { unResolve } from '.';
import { describeVue } from '../_testUtils/vue';
import { unSignal } from '../unSignal';

describeVue('unResolve', () => {
it('should resolve to an Vue Ref', () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/unuse/src/useEventListener/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { unComputed, unWatch } from 'unuse-reactivity';
import { IS_CLIENT } from '../isClient';
import { isObject } from '../isObject';
import { toArray } from '../toArray';
import { tryOnScopeDispose } from '../tryOnScopeDispose';
import type { MaybeUnRef } from '../unAccess';
import { unAccess } from '../unAccess';
import { unComputed } from '../unComputed';
import { unRefElement } from '../unRefElement';
import { unWatch } from '../unWatch';

export const defaultWindow = IS_CLIENT
? // eslint-disable-next-line unicorn/prefer-global-this
Expand Down
3 changes: 1 addition & 2 deletions packages/unuse/src/useIntervalFn/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { unSignal, unWatch } from 'unuse-reactivity';
import { IS_CLIENT } from '../isClient';
import { toUnSignal } from '../toUnSignal';
import { tryOnScopeDispose } from '../tryOnScopeDispose';
import type { MaybeUnRef } from '../unAccess';
import { isUnRef, unAccess } from '../unAccess';
import type { ReadonlyUnResolveReturn } from '../unResolve';
import { unResolve } from '../unResolve';
import { unSignal } from '../unSignal';
import { unWatch } from '../unWatch';

export interface Pausable {
/**
Expand Down
3 changes: 1 addition & 2 deletions packages/unuse/src/useWebSocket/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable unicorn/prefer-add-event-listener */
import { unSignal, unWatch } from 'unuse-reactivity';
import { IS_CLIENT } from '../isClient';
import { IS_WORKER } from '../isWorker';
import { toUnSignal } from '../toUnSignal';
Expand All @@ -7,8 +8,6 @@ import type { MaybeUnRef, UnRef } from '../unAccess';
import { unAccess } from '../unAccess';
import type { WritableUnResolveReturn } from '../unResolve';
import { unResolve } from '../unResolve';
import { unSignal } from '../unSignal';
import { unWatch } from '../unWatch';
import { useEventListener } from '../useEventListener';
import { useIntervalFn } from '../useIntervalFn';

Expand Down
1 change: 1 addition & 0 deletions packages/unuse/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export default defineConfig({
exports: true,
platform: 'neutral',
publint: true,
noExternal: ['unuse-reactivity'],
});
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0