npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svelte-firebase-cms

v0.0.8

Published

Svelte library for FireFlutter

Downloads

12

Readme

SvelteFire

Svelte library for FireFlutter

Run

  • To run with .env.dev, run npm run dev -- --open --mode dev.

Initialization

The recommended way of intialization is that put the code SvelteFire.init() inside src/routes/+layout.svelte.

import { app } from '$lib/client/init.firebase.client';
import { SvelteFire } from '$lib/sveltefire/svelte-fire';
SvelteFire.init({ app });

Below is the src/lib/client/init.firebase.client.

import { initializeApp } from "firebase/app";
const firebaseConfig: { [key: string]: string; } = {
    apiKey: "AI....fU",
    authDomain: "silbus.firebaseapp.com",
    databaseURL: "https://silb.....st1.firebasedatabase.app",
    projectId: "silbus",
    storageBucket: "silbus.appspot.com",
    messagingSenderId: "575893880018",
    appId: "1:575.....fc10b",
    measurementId: "G-3KQTNK89WP"
};
export const app = initializeApp(firebaseConfig);

Login

To use sveltefire, the user must login. SvelteFire does not provide any login mechanism. It's up to you how you desgin your app. You may use email/password login or Phone sign-in, Google sign-in, etc.

Common Patterns

Fetch Data from Firestore for Authenticated Users

First, Use the SignedIn component to access the UID of the current user. Second, pass that UID to the Doc or Collection component to fetch a Firestore document owned by that user.

  <SignedIn let:user>
    <Doc ref={`users/${user.uid}`} let:data={user}>
        <h2>{user.displayName}</h2>
    </Doc>
  </SignedIn>

Hydrate data from server side

The component Doc, Collection, Value, ValueList hydrates the SSR data.

Use the hydration data from svelte kit into the components of Value, ValueList, Doc, Collection. The HTML source code will have the data of the hydration.

NotSignedIn

<NotSignedIn>
	<a href="/user/sign-in">SignIn</a>
</NotSignedIn>

SignedIn

The SignedIn component renders content for the current user. It is a wrapper around the userStore. If the user is not signed in, the children will not be rendered.

Slot Props

  • user - The current Firebase user
  • auth - The current Firebase auth instance
  • signOut - A function to sign out the current user
<SignedIn let:user let:signOut let:auth>
	You are signed in with {user.uid}
	<button on:click={signOut}>Sign Out</button>
	{auth.currentUser?.email}
</SignedIn>

Value

Get a value of node and display

<Value path="post-all-summaries/-NvgtY78Qcowz-zwjRnN" hydrate={{ title: 'THIS IS TITLE' }} let:data>
	{#each Object.keys(data) as key}
		{key}: {data[key]}
	{/each}
</Value>

ValueList

Display a list of value node

<ValueList path="post-all-summaries" let:data>
	{#each data as item}
		<p>
			{#each Object.keys(item) as key}
				{key}: {item[key]}
			{/each}
		</p>
	{/each}
</ValueList>

Doc

Display a document.

Collection

Display lists of documents in that collection

  • infiniteScroll is an option to scroll infinitely.

Upload

display a UI for file upload into storage

MyValue

UserDoc

Developing

Once you've created a project and installed dependencies with npm install (or pnpm install or yarn), start a development server:

npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open

Everything inside src/lib is part of your library, everything inside src/routes can be used as a showcase or preview app.

Building

To build your library:

npm run package

To create a production version of your showcase app:

npm run build

You can preview the production build with npm run preview.

To deploy your app, you may need to install an adapter for your target environment.

Publishing

Go into the package.json and give your package the desired name through the "name" option. Also consider adding a "license" field and point it to a LICENSE file which you can create from a template (one popular option is the MIT license).

To publish your library to npm:

npm publish

Forum List

  • The InfiniteValueList component will not be destroyed and mounted if it is used in same page with different path. So, observe the chagnes of path and reset it.
<script lang="ts">
	import { page } from '$app/stores';
	import InfiniteValueList from '$lib/components/InfiniteValueList.svelte';
	import { onMount } from 'svelte';

	export let data;

	let controller: InfiniteValueList;
	let unsubscribe: () => void;

	onMount(() => {
		/// When categry changes, reset the store and fetch new data
		unsubscribe = page.subscribe(() => {
			controller?.onReset();
		});
	});

	onDestroy(() => {
		unsubscribe?.();
	});
</script>

<InfiniteValueList
	path={'posts-summary/' + data.category}
	hydrate={data.posts}
	let:value
	bind:this={controller}
>
	<p style="padding: 2em;">
		<a href="/forum/{data.category}/{value.key}">{value.title}</a>
		<span style="display: block;"></span>{value.key}
		<span style="display: block; margin-top:1em"
			>{new Date(value['createdAt']).toLocaleString()}</span
		>
	</p>

	<p slot="noMoreData" let:length>
		# No of post loaded: #{length}
		<br />
		No more posts
	</p>
	<p slot="loading">Loading data...</p>
</InfiniteValueList>