Skip to content

Commit

Permalink
Merge pull request #167 from Neovici/feat/pion
Browse files Browse the repository at this point in the history
feat: update to pion
  • Loading branch information
megheaiulian authored Jan 11, 2024
2 parents e3c3b89 + 3d3dbfe commit 4f5efd0
Show file tree
Hide file tree
Showing 38 changed files with 152 additions and 194 deletions.
67 changes: 11 additions & 56 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"./memoize": "./dist/memoize.js"
},
"dependencies": {
"haunted": "^5.0.0"
"@pionjs/pion": "^2.0.0"
},
"devDependencies": {
"@commitlint/cli": "^18.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/directives/consume.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Context, ContextDetail } from 'haunted/lib/create-context';
import { contextEvent } from 'haunted/lib/symbols';
import { Context, ContextDetail } from '@pionjs/pion/lib/create-context';
import { contextEvent } from '@pionjs/pion/lib/symbols';
import { AttributePart, noChange } from 'lit-html';
import { AsyncDirective, directive } from 'lit-html/async-directive.js';
import { ChildPart, DirectiveParameters } from 'lit-html/directive.js';
Expand Down
4 changes: 2 additions & 2 deletions src/directives/provide.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Context, ContextDetail } from 'haunted/lib/create-context';
import { contextEvent } from 'haunted/lib/symbols';
import { Context, ContextDetail } from '@pionjs/pion/lib/create-context';
import { contextEvent } from '@pionjs/pion/lib/symbols';
import { noChange, nothing } from 'lit-html';
import { AsyncDirective, directive } from 'lit-html/async-directive.js';
import { ChildPart } from 'lit-html/directive.js';
Expand Down
2 changes: 1 addition & 1 deletion src/elements/cz-icon.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { html, svg } from 'lit-html';
import { ifDefined } from 'lit-html/directives/if-defined';
import { component } from 'haunted';
import { component } from '@pionjs/pion';

interface Ico {
icon?: ReturnType<typeof svg>;
Expand Down
2 changes: 1 addition & 1 deletion src/elements/cz-spinner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { component, html } from 'haunted';
import { component, html } from '@pionjs/pion';

export const Spinner = () => html`<style>
@keyframes rotating {
Expand Down
2 changes: 1 addition & 1 deletion src/haunted-polymer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
render,
GenericRenderer,
ComponentOrVirtualComponent,
} from 'haunted';
} from '@pionjs/pion';
import { ChildPart } from 'lit-html';
import { Rec } from './object';

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-abort-signal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo } from 'haunted';
import { useEffect, useMemo } from '@pionjs/pion';

export const useAbortSignal = () => {
const { controller, signal } = useMemo(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-debounce-raf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect } from 'haunted';
import { useState, useEffect } from '@pionjs/pion';

/**
* Debounces a value by updating it via a double requestAnimationFrame call.
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-drag-items.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback } from 'haunted';
import { useCallback } from '@pionjs/pion';
import { useMeta } from './use-meta';
import { parse } from '../number';

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-dropped-files.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useCallback } from 'haunted';
import { useState, useCallback } from '@pionjs/pion';
import { useHandleDrop } from './use-handle-drop';

export const useDroppedFiles = <T extends HTMLElement>(el: T) => {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-handle-drop.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from 'haunted';
import { useEffect } from '@pionjs/pion';

export const useHandleDrop = <T extends HTMLElement>(
el: T,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-host-bounds.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useLayoutEffect, useState } from 'haunted';
import { useLayoutEffect, useState } from '@pionjs/pion';
import { useHost } from './use-host';

const useHostBounds = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-host.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hook, Hook } from 'haunted';
import { hook, Hook } from '@pionjs/pion';

type UseHost = <T extends HTMLElement>()=>T;

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-imperative-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Hook, hook, State } from 'haunted';
import { Hook, hook, State } from '@pionjs/pion';

export const useImperativeApi = hook(
class<A, D = unknown> extends Hook<[A, D[]], void> {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-meta.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo } from 'haunted';
import { useMemo } from '@pionjs/pion';
import { Rec } from '../object';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-notify-property.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from 'haunted';
import { useEffect } from '@pionjs/pion';
import { useHost } from './use-host';

const UPPER = /([A-Z])/gu;
Expand Down
75 changes: 35 additions & 40 deletions src/hooks/use-promise.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,50 @@
import {
useReducer,
useEffect
} from 'haunted';
import {
reduce,
action
} from '../reduce';
import { useReducer, useEffect } from '@pionjs/pion';
import { reduce, action } from '../reduce';

const
states = {
const states = {
pending: 'pending',
rejected: 'rejected',
resolved: 'resolved'
resolved: 'resolved',
},
initial = {
error: undefined,
result: undefined,
state: states.pending
state: states.pending,
},
pending = action(states.pending),
resolved = action(states.resolved, result => ({ result })),
rejected = action(states.rejected, error => ({ error })),
resolved = action(states.resolved, (result) => ({ result })),
rejected = action(states.rejected, (error) => ({ error })),
reducer = reduce(initial, [
[pending, () => ({
error: undefined,
result: undefined,
state: states.pending
})],
[
pending,
() => ({
error: undefined,
result: undefined,
state: states.pending,
}),
],

[resolved, (state, { result }) => ({
error: undefined,
result,
state: states.resolved
})],
[
resolved,
(state, { result }) => ({
error: undefined,
result,
state: states.resolved,
}),
],

[rejected, (state, { error }) => ({
error,
result: undefined,
state: states.rejected
})]
[
rejected,
(state, { error }) => ({
error,
result: undefined,
state: states.rejected,
}),
],
]);

export const usePromise = promise => {
const [
{
error,
result,
state
},
dispatch
] = useReducer(reducer, initial);
export const usePromise = (promise) => {
const [{ error, result, state }, dispatch] = useReducer(reducer, initial);

useEffect(() => {
if (!promise) {
Expand All @@ -61,8 +56,8 @@ export const usePromise = promise => {
dispatch(pending());

promise.then(
result => !canceled && dispatch(resolved(result)),
error => !canceled && dispatch(rejected(error))
(result) => !canceled && dispatch(resolved(result)),
(error) => !canceled && dispatch(rejected(error)),
);

return () => {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-property.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useCallback } from 'haunted';
import { useEffect, useCallback } from '@pionjs/pion';
import { useMeta } from './use-meta';
import { useHost } from './use-host';
import { invoke } from '../function';
Expand Down
19 changes: 11 additions & 8 deletions src/tag.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { html as htm } from 'haunted';
import { html as htm } from 'lit-html';

const html: typeof htm = (arr, ...thru) =>
htm(
Object.assign(arr, { raw: true }) as unknown as TemplateStringsArray,
...thru
...thru,
);

export const
/**
export const /**
* Dynamic component support for lit-html.
*
* Normally lit-html does not support interpolating the component tag, but we can trick it
Expand All @@ -28,7 +27,11 @@ export const
*
* @return {TemplateResult} The lit template result.
*/
tag = (strings: string[], component: string, ...values: unknown[]) => html([
strings[0] + component + strings[1],
...strings.slice(2)
] as unknown as TemplateStringsArray, ...values);
tag = (strings: string[], component: string, ...values: unknown[]) =>
html(
[
strings[0] + component + strings[1],
...strings.slice(2),
] as unknown as TemplateStringsArray,
...values,
);
5 changes: 2 additions & 3 deletions test/array.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { assert } from '@open-wc/testing';

import { array, without, chunk, intersect } from '../src/array';

const empty = [],
Expand All @@ -24,9 +23,9 @@ suite('array', () => {
assert.lengthOf(
without(
[{ id: 1 }, { id: 2 }],
(o) => o.id
(o) => o.id,
)([{ id: 1 }, { id: 2 }, { id: 3 }]),
1
1,
);
});
test('chunk', () => {
Expand Down
Loading

0 comments on commit 4f5efd0

Please sign in to comment.