FastComments.com

Add Comments to Your SolidJS App


Dit is de officiële SolidJS-bibliotheek voor FastComments.

Voeg live reacties, chat- en review-widgets toe aan je SolidJS-app.

Repository

Bekijk op GitHub


Installeren Internal Link

npm install fastcomments-solidjs

Gebruik Internal Link

import { FastCommentsCommentWidget } from 'fastcomments-solidjs';

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

Reageren op configuratiewijzigingen (imperatieve handle) Internal Link

Solid volgt niet automatisch diepe mutaties op willekeurige objecten, dus configwijzigingen na de eerste render moeten expliciet worden doorgegeven. Elke widget accepteert een apiRef die een handle retourneert; roep handle.update(partial) aan vanuit een createEffect om reactiviteit aan te sturen:

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() is veilig om op elk moment aan te roepen:

  • 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.

Imperatieve handle API

interface WidgetHandle<Config> {
  getInstance: () => WidgetInstance | null;   // latest live instance (or null before mount)
  onInstance: (cb: (instance: WidgetInstance) => void) => void; // fires once instance is ready
  update: (partial: Partial<Config>) => void; // merge-and-push config
}

Gebruik getInstance() voor imperatieve acties die niet door .update() worden afgedekt, bijv. openProfile:

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

Componenten Internal Link

Elk widget uit fastcomments-react is beschikbaar onder dezelfde naam:

Component Handle type Ingesloten embed
FastCommentsCommentWidget FastCommentsCommentWidgetHandle Hoofd-widget voor livecommentaar
FastCommentsCommentCountWidget FastCommentsCommentCountWidgetHandle Inline-badge met aantal reacties
FastCommentsLiveChatWidget FastCommentsLiveChatWidgetHandle Streaming livechat-widget
FastCommentsCollabChatWidget FastCommentsCollabChatWidgetHandle Samenwerkende chat verankerd aan tekst
FastCommentsImageChatWidget FastCommentsImageChatWidgetHandle Regiogebaseerde afbeeldingsreacties
FastCommentsRecentCommentsWidget FastCommentsRecentCommentsWidgetHandle Feed met recente reacties
FastCommentsRecentDiscussionsWidget FastCommentsRecentDiscussionsWidgetHandle Feed met recente discussies
FastCommentsReviewsSummaryWidget FastCommentsReviewsSummaryWidgetHandle Samenvatting van sterrenbeoordelingen
FastCommentsTopPagesWidget FastCommentsTopPagesWidgetHandle Ranglijst van pagina's met meeste reacties
FastCommentsUserActivityFeedWidget FastCommentsUserActivityFeedWidgetHandle Activiteitstijdlijn per gebruiker

Widgets die aan een bestaand element worden gekoppeld

FastCommentsCollabChatWidget en FastCommentsImageChatWidget worden gemount in een door de aanroeper aangeleverd element. Geef een targetRef-toegangsfunctie door die het element teruggeeft zodra het is gemonteerd:

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}
      />
    </>
  );
}

Regio's

Geef region="eu" op om het widgetverkeer via het EU-cluster te routeren.

Voorbeelden Internal Link

Een volledige showcase-app bevindt zich in examples/example-showcase/. Het weerspiegelt de React showcase en behandelt elke widget plus veelvoorkomende flows (donkere modus, paginering, SSO, callbacks).

cd examples/example-showcase
npm install
npm run dev

Bouwen Internal Link

npm install
npm run build       # bibliotheek -> dist/
npm test            # vitest smoke-test
npm run build:demo  # showcase -> demo-dist/

Hulp nodig?

Als u problemen ondervindt of vragen heeft over de SolidJS Library, gelieve:

Bijdragen

Bijdragen zijn welkom! Bezoek de GitHub-repository voor richtlijnen voor bijdragen.