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

@quenty/servicebag

v11.10.0

Published

Service providing mechanisms for Nevermore

Downloads

1,524

Readme

ServiceBag

Service providing mechanisms for Nevermore

Installation

npm install @quenty/servicebag --save

Goals

  • Remove requirement for many services to be loaded
  • Make installing new modules really easy
  • Make testing easier
  • Reduce maintaince costs
  • Explicitly declare service pattern
  • Force declaration of service usage
  • Make it easy to trace service dependencies

Requirements

  • Initialize dependent services using :Init()
  • Start dependent services using :Start()
  • Retrieve services is easy
  • Don't have to list off every service in the game
  • Services don't load until we ask them to
  • Circular dependencies allowed

Like-to-have

  • Dependency injection for tests
  • Works with type system GetService<IService>()
  • Async initialization (return promises instead of blocking)
  • Dependency graph safe (i.e. recursive service requirement )
  • Services are protected from another service erroring

Stretch goals

  • Handles services for actors (remove global code)

Ideas

  • Inject a ServiceBag

Rules

  1. Each service will be identified by its module
  2. Each service will be initialized once
  3. If we require a service, we will not have to declare subservices
-- Main script
local serviceBag = require("ServiceBag").new()

serviceBag:AddService(require("TransparencyService"))

serviceBag:Init()
serviceBag:Start()
-- Other script
local TransparencyService = require("TransparencyService") -- force declaration at top

local TestClass = {}
TestClass.ClassName = "TestClass"
TestClass.__index = TestClass

function TestClass.new(serviceBag)
	local self = setmetatable({}, TestClass)

	self._serviceProvider = assert(serviceBag, "No serviceBag")

	self._transparencyService = self._serviceProvider:GetRequiredService(TransparencyService)
	
	return self
end

return TestClass
local DialogPane = setmetatable({}, BasicPane)
DialogPane.ClassName = "DialogPane"
DialogPane.__index = DialogPane

function DialogPane.new(serviceBag)
  local self = setmetatable(BasicPane.new(serviceBag:GetService(DialogTemplatesClient):Clone("DialogPaneTemplate")), DialogPane)

  self._theme = Instance.new("StringValue")
  self._theme.Value = "Light"
  self._maid:GiveTask(self._theme)

  self._dialogInput = DialogInput.new()
  self._maid:GiveTask(self._dialogInput)

Classes versus singletons

Right now services and classes aren't the same. There's no contract to transform a class with lifetime into a service. However, because some of our services actually implement a .new() method (i.e. service definitions can be classes), we can't differentiate easily.

The issue is around life-cycle.

  1. Service.new() can either be a constructor which establishes just data for the service or...
  2. Service.new() can actually establish state data.

Other service providers solve this issue by doing the following...

  1. Separating out the service identifier from the actual service definition (interfaces)
  2. Separating out the addition of services from the actual services

We inherently don't want to separate out interfaces yet because we don't know what the actors or tie-interfaces for hot reloading will even look like.

It's important that we don't define this yet because there's a good chance separation at the service layer will be very important (i.e. we'll want to observe service state existing).

Potential solution: Interface provision

We could establish a contract that providing an interface will be allowed. That is, a service can return a value it'd like to use as an interface instead. We may need to wait until we resolve these other problems first.

Major changes in the future

  1. Require-by-name
  2. Interfaces as definition
  3. Hot reloading
  4. Async interfaces