FastComments.com

Add Comments to Your SolidJS App

ื–ื•ื”ื™ ื”ืกืคืจื™ื™ื” ื”ืจืฉืžื™ืช ืฉืœ FastComments ืœโ€‘SolidJS.

ื”ื˜ืžืข ื•ื•ื™ื“ื’'ื˜ื™ื ืฉืœ ืชื’ื•ื‘ื•ืช ื‘ื–ืžืŸ ืืžืช, ืฆ'ืื˜ ื•ื‘ื™ืงื•ืจื•ืช ื‘ืืคืœื™ืงืฆื™ื™ืช SolidJS ืฉืœืš.

ืžืื’ืจ

ืฆืคื” ื‘โ€‘GitHub


ื”ืชืงื ื” Internal Link

npm install fastcomments-solidjs

ืฉื™ืžื•ืฉ Internal Link

import { FastCommentsCommentWidget } from 'fastcomments-solidjs';

export default function App() {
  return <FastCommentsCommentWidget tenantId="demo" urlId="some-page-id" />;
}

ืชื’ื•ื‘ื” ืœืฉื™ื ื•ื™ื™ื ื‘ืชืฆื•ืจื” (ื˜ื™ืคื•ืœ ืื™ืžืคืจื˜ื™ื‘ื™) Internal Link

Solid ืœื ืขื•ืงื‘ืช ื‘ืื•ืคืŸ ืื•ื˜ื•ืžื˜ื™ ืื—ืจื™ ืฉื™ื ื•ื™ื™ื ืขืžื•ืงื™ื ืขืœ ืื•ื‘ื™ื™ืงื˜ื™ื ืืงืจืื™ื™ื, ื›ืš ืฉืฉื™ื ื•ื™ื™ื ื‘ืงื•ื ืคื™ื’ื•ืจืฆื™ื” ืœืื—ืจ ื”-render ื”ืจืืฉื•ืŸ ื—ื™ื™ื‘ื™ื ืœื”ื™ื•ืช ืžื•ืขื‘ืจื™ื ื‘ืžืคื•ืจืฉ. ื›ืœ ื•ื•ื™ื“ื’'ื˜ ืžืงื‘ืœ apiRef ืฉืžื—ื–ื™ืจ handle; ืงืจืื• ืœ-handle.update(partial) ืžืชื•ืš createEffect ื›ื“ื™ ืœื”ื ื™ืข ืจื™ืืงื˜ื™ื‘ื™ื•ืช:

import { createEffect, createSignal } from 'solid-js';
import { FastCommentsCommentWidget, type FastCommentsCommentWidgetHandle } from 'fastcomments-solidjs';

export default function Paginated() {
  const [page, setPage] = createSignal(0);
  let handle: FastCommentsCommentWidgetHandle | undefined;
  createEffect(() => handle?.update({ urlId: `product-${page()}` }));

  return (
    <>
      <button onClick={() => setPage(page() + 1)}>next</button>
      <FastCommentsCommentWidget
        apiRef={(h) => (handle = h)}
        tenantId="demo"
        urlId={`product-${page()}`}
      />
    </>
  );
}

update() ื‘ื˜ื•ื— ืœืงืจื™ืื” ื‘ื›ืœ ืขืช:

  • Before the script has loaded: the partial is stashed and applied at init.
  • During an async init (reviews-summary, user-activity-feed): the partial is queued and applied when the callback resolves.
  • After init: it forwards straight to the live widget's .update() method.

API ืื™ืžืคืจื˜ื™ื‘ื™ ืฉืœ ื”-handle

interface WidgetHandle<Config> {
  getInstance: () => WidgetInstance | null;   // ื”ืžื•ืคืข ื”ื—ื™ ื”ืื—ืจื•ืŸ (ืื• null ืœืคื ื™ ื”ื”ืจื›ื‘ื”)
  onInstance: (cb: (instance: WidgetInstance) => void) => void; // ื ืงืจื ืคืขื ืื—ืช ื›ืฉื”ืžื•ืคืข ืžื•ื›ืŸ
  update: (partial: Partial<Config>) => void; // ืžื™ื–ื•ื’ ื•ื“ื—ื™ืคืช ื”ืงื•ื ืคื™ื’ื•ืจืฆื™ื”
}

Use getInstance() for imperative actions that aren't covered by .update(), e.g. openProfile:

const openProfile = () =>
  (handle?.getInstance() as { openProfile?: (o: { userId: string }) => void } | null)
    ?.openProfile?.({ userId: 'demo' });

ืจื›ื™ื‘ื™ื Internal Link

ื›ืœ ื•ื•ื™ื“ื’'ื˜ ืžึพfastcomments-react ื–ืžื™ืŸ ืชื—ืช ื”ืฉืžื•ืช ื”ื‘ืื™ื:

Component Handle type Embed loaded
FastCommentsCommentWidget FastCommentsCommentWidgetHandle ื•ื™ื“ื’'ื˜ ืชื’ื•ื‘ื•ืช ื—ื™ื•ืช ืจืืฉื™
FastCommentsCommentCountWidget FastCommentsCommentCountWidgetHandle ืชื’ ืกืคื™ืจืช ืชื’ื•ื‘ื•ืช ืคื ื™ืžื™
FastCommentsLiveChatWidget FastCommentsLiveChatWidgetHandle ื•ื™ื“ื’'ื˜ ืฆ'ืื˜ ื—ื™ ื–ื•ืจื
FastCommentsCollabChatWidget FastCommentsCollabChatWidgetHandle ืฆ'ืื˜ ืฉื™ืชื•ืคื™ ืžืขื•ื’ืŸ ืœื˜ืงืกื˜
FastCommentsImageChatWidget FastCommentsImageChatWidgetHandle ืชื’ื•ื‘ื•ืช ืชืžื•ื ื” ืžื‘ื•ืกืกื•ืช ืื–ื•ืจื™ื
FastCommentsRecentCommentsWidget FastCommentsRecentCommentsWidgetHandle ืคื™ื“ ืชื’ื•ื‘ื•ืช ืื—ืจื•ื ื•ืช
FastCommentsRecentDiscussionsWidget FastCommentsRecentDiscussionsWidgetHandle ืคื™ื“ ื“ื™ื•ื ื™ื ืื—ืจื•ื ื™ื
FastCommentsReviewsSummaryWidget FastCommentsReviewsSummaryWidgetHandle ืกื™ื›ื•ื ื“ื™ืจื•ื’ ื‘ื›ื•ื›ื‘ื™ื
FastCommentsTopPagesWidget FastCommentsTopPagesWidgetHandle ื˜ื‘ืœืช ืžื•ื‘ื™ืœื™ื ืฉืœ ื“ืคื™ื ืขื ื”ื›ื™ ื”ืจื‘ื” ืชื’ื•ื‘ื•ืช
FastCommentsUserActivityFeedWidget FastCommentsUserActivityFeedWidgetHandle ืฆื™ืจ ื–ืžืŸ ืคืขื™ืœื•ืช ืœื›ืœ ืžืฉืชืžืฉ

ื•ื•ื™ื“ื’'ื˜ื™ื ืฉืžืชื—ื‘ืจื™ื ืœืืœืžื ื˜ ืงื™ื™ื

FastCommentsCollabChatWidget ื•ึพFastCommentsImageChatWidget ืžื•ืฆืžื“ื™ื ืืœ ืืœืžื ื˜ ืฉืžืกื•ืคืง ืขืœ ื™ื“ื™ ื”ืงื•ืจื. ื”ืขื‘ืจ ืคื•ื ืงืฆื™ื™ืช ื’ื™ืฉื” (targetRef) ืฉืžื—ื–ื™ืจื” ืืช ื”ืืœืžื ื˜ ืœืื—ืจ ืฉื”ื•ื ืžื•ืชืงืŸ:

import { FastCommentsImageChatWidget } from 'fastcomments-solidjs';

export default function ImageChat() {
  let img: HTMLImageElement | undefined;
  return (
    <>
      <img ref={img} src="/screenshot.png" alt="" />
      <FastCommentsImageChatWidget
        tenantId="demo"
        urlId="my-image"
        targetRef={() => img}
      />
    </>
  );
}

ืื–ื•ืจื™ื

ื”ืขื‘ืจ region="eu" ื›ื“ื™ ืœื ืชื‘ ืืช ื”ืชื ื•ืขื” ืฉืœ ื”ื•ื•ื™ื“ื’'ื˜ ื“ืจืš ืืฉื›ื•ืœ ื”โ€‘EU.

ื”ืฆื’ื” Internal Link

ืืคืœื™ืงืฆื™ื™ืช ืชืฆื•ื’ื” ืžืœืื” ื ืžืฆืืช ื‘examples/example-showcase/. ื”ื™ื ืžืฉืงืคืช ืืช ืชืฆื•ื’ืช React ื•ืžื›ืกื” ืืช ื›ืœ ื”ื•ื•ื™ื“ื’'ื˜ื™ื ื•ื›ืŸ ื–ืจื™ืžื•ืช ื ืคื•ืฆื•ืช (ืžืฆื‘ ื›ื”ื”, ืขื™ืžื•ื“, SSO, ืงืจื™ืื•ืช ื—ื–ืจื”).

cd examples/example-showcase
npm install
npm run dev

ื‘ื ื™ื™ื” Internal Link

npm install
npm run build       # ืกืคืจื™ื™ื” -> dist/
npm test            # ื‘ื“ื™ืงื” ื‘ืกื™ืกื™ืช ืฉืœ vitest
npm run build:demo  # ืชืฆื•ื’ื” -> demo-dist/

ื–ืงื•ืงื™ื ืœืขื–ืจื”?

ืื ืืชื ื ืชืงืœื™ื ื‘ื‘ืขื™ื•ืช ืื• ื™ืฉ ืœื›ื ืฉืืœื•ืช ืœื’ื‘ื™ ืกืคืจื™ื™ืช SolidJS, ืื ื:

ื”ืฉืชืชืคื•ืช

ืชืจื•ืžื•ืช ืžืชืงื‘ืœื•ืช ื‘ื‘ืจื›ื”! ืื ื ื‘ืงืจื• ื‘-ืžืื’ืจ ื”-GitHub ืœื”ื ื—ื™ื•ืช ืœืชืจื•ืžื”.