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

edge-stacks

v2.0.0-0

Published

Stacks implementation for Edge

Downloads

6

Readme

Edge stacks

gh-workflow-image typescript-image npm-image license-image synk-image

Edge stacks allow you to create content placeholders and push content inside them from other parts of your template. For example, You can create a placeholder for inline JavaScript in the head tag and push script tags inside it from components.

  1. Following is the markup of a layout file.

    <!doctype html>
    <html lang="en">
      <head>
        <!-- Creating a stack for JavaScript -->
        @stack('js')
      </head>
      <body>
        @!component('button', { message: 'Hello 👋' })
      </body>
    </html>
  2. Now, let's create the button component. We will call a frontend JavaScript method sayMessage every time someone clicks the button.

    <button click="sayMessage('{{ message }}')">Click me to get the message</button>
  3. Finally, we must create the sayMessage function. With stacks, you can write JavaScript within the same component file.

    <button onclick="sayMessage('{{ message }}')">Click me to get the message</button>
    
    @pushTo('js')
    <script>
      function sayMessage(message) {
        alert(message)
      }
    </script>
    @end

The pushTo tag accepts the stack's name in which to push the content. The above example will push the content inside the js stack we defined inside the layout file.

However, the @pushTo tag will push contents as many times as you import the component, which can be a deal breaker in this case.

Therefore, we ship with another @pushOnceTo tag. It pushes the content to a stack only once, regardless of how many times you import the component.

Setup

You can install the package from the npm package registry as follows.

npm i edge-stacks

And use it as a plugin as follows.

import { Edge } from 'edge.js'
import { edgeStacks } from 'edge-stacks'

const edge = new Edge()
edge.use(edgeStacks)

AdonisJS users can register the plugin with the View object. Then, to write the setup code, you can create a preload file.

import View from '@ioc:Adonis/Core/View'
import { edgeStacks } from 'edge-stacks'

View.use(edgeStacks)

Tags

Following is the list of tags registered by this package.

@stack

The @stack tag creates a named placeholder where other parts of your template can push content. The tag only accepts a single argument as the name of the stack.

@stack('js') @stack('css')

Calling @stack multiple times with the same name will result in a runtime error.

<!-- ❌ Fails -->
@stack('js') @stack('js')
<!-- ✅ Works -->
@if(foo) @stack('js') @elseif (bar) @stack('js') @end

@pushTo

The @pushTo tag pushes the contents inside a given named stack. The tag accepts a single argument as the stack name, followed by the content as the tag body.

@pushTo('js')
<script defer></script>
@end

Calling @pushTo before registering a stack will result in an error.

<!-- ❌ Fails, since the stack is created afterward -->
@pushTo('js') @end @stack('js')

@pushOnceTo

The @pushOnceTo tag is the same as the @pushTo tag. However, it pushes the contents only once. The @pushOnceTo tag is helpful inside components and partials. So that you can import them multiple times, but the push side-effect happens only once.

@pushOnceTo('js')
<script defer></script>
@end