Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lit-labs/context

Package Overview
Dependencies
Maintainers
11
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lit-labs/context - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2-pre.0

2

development/lib/context-request-event.d.ts

@@ -20,3 +20,3 @@ /**

*/
export declare type ContextCallback<ValueType> = (value: ValueType, unsubscribe?: () => void) => void;
export type ContextCallback<ValueType> = (value: ValueType, unsubscribe?: () => void) => void;
/**

@@ -23,0 +23,0 @@ * Interface definition for a ContextRequest

@@ -21,3 +21,2 @@ /**

constructor(host, contextOrOptions, callback, subscribe) {
var _a;
this.subscribe = false;

@@ -63,3 +62,3 @@ this.provided = false;

this.callback = options.callback;
this.subscribe = (_a = options.subscribe) !== null && _a !== void 0 ? _a : false;
this.subscribe = options.subscribe ?? false;
}

@@ -69,3 +68,3 @@ else {

this.callback = callback;
this.subscribe = subscribe !== null && subscribe !== void 0 ? subscribe : false;
this.subscribe = subscribe ?? false;
}

@@ -72,0 +71,0 @@ this.host.addController(this);

@@ -9,3 +9,3 @@ /**

*/
export declare type Context<KeyType, ValueType> = KeyType & {
export type Context<KeyType, ValueType> = KeyType & {
__context__: ValueType;

@@ -16,7 +16,7 @@ };

*/
export declare type ContextKey<KeyType, ValueType> = Context<KeyType, ValueType>;
export type ContextKey<KeyType, ValueType> = Context<KeyType, ValueType>;
/**
* A helper type which can extract a Context value type from a Context type
*/
export declare type ContextType<Key extends Context<unknown, unknown>> = Key extends Context<unknown, infer ValueType> ? ValueType : never;
export type ContextType<Key extends Context<unknown, unknown>> = Key extends Context<unknown, infer ValueType> ? ValueType : never;
/**

@@ -23,0 +23,0 @@ * Creates a typed Context.

@@ -51,8 +51,7 @@ /**

const descriptor = Object.getOwnPropertyDescriptor(ctor.prototype, name);
const oldSetter = descriptor === null || descriptor === void 0 ? void 0 : descriptor.set;
const oldSetter = descriptor?.set;
const newDescriptor = {
...descriptor,
set: function (value) {
var _a;
(_a = controllerMap.get(this)) === null || _a === void 0 ? void 0 : _a.setValue(value);
controllerMap.get(this)?.setValue(value);
if (oldSetter) {

@@ -59,0 +58,0 @@ oldSetter.call(this, value);

@@ -15,13 +15,2 @@ /**

export class ValueNotifier {
constructor(defaultValue) {
this.callbacks = new Map();
this.updateObservers = () => {
for (const [callback, disposer] of this.callbacks) {
callback(this._value, disposer);
}
};
if (defaultValue !== undefined) {
this.value = defaultValue;
}
}
get value() {

@@ -40,2 +29,13 @@ return this._value;

}
constructor(defaultValue) {
this.callbacks = new Map();
this.updateObservers = () => {
for (const [callback, disposer] of this.callbacks) {
callback(this._value, disposer);
}
};
if (defaultValue !== undefined) {
this.value = defaultValue;
}
}
addCallback(callback, subscribe) {

@@ -42,0 +42,0 @@ if (subscribe) {

@@ -20,3 +20,3 @@ /**

*/
export declare type ContextCallback<ValueType> = (value: ValueType, unsubscribe?: () => void) => void;
export type ContextCallback<ValueType> = (value: ValueType, unsubscribe?: () => void) => void;
/**

@@ -23,0 +23,0 @@ * Interface definition for a ContextRequest

@@ -6,3 +6,3 @@ import{ContextRequestEvent as t}from"../context-request-event.js";

* SPDX-License-Identifier: BSD-3-Clause
*/class s{constructor(t,s,i,h){var e;if(this.subscribe=!1,this.provided=!1,this.value=void 0,this.t=(t,s)=>{this.unsubscribe&&(this.unsubscribe!==s&&(this.provided=!1,this.unsubscribe()),this.subscribe||this.unsubscribe()),this.value=t,this.host.requestUpdate(),this.provided&&!this.subscribe||(this.provided=!0,this.callback&&this.callback(t,s)),this.unsubscribe=s},this.host=t,void 0!==s.context){const t=s;this.context=t.context,this.callback=t.callback,this.subscribe=null!==(e=t.subscribe)&&void 0!==e&&e}else this.context=s,this.callback=i,this.subscribe=null!=h&&h;this.host.addController(this)}hostConnected(){this.dispatchRequest()}hostDisconnected(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=void 0)}dispatchRequest(){this.host.dispatchEvent(new t(this.context,this.t,this.subscribe))}}export{s as ContextConsumer};
*/class s{constructor(t,s,i,h){if(this.subscribe=!1,this.provided=!1,this.value=void 0,this.t=(t,s)=>{this.unsubscribe&&(this.unsubscribe!==s&&(this.provided=!1,this.unsubscribe()),this.subscribe||this.unsubscribe()),this.value=t,this.host.requestUpdate(),this.provided&&!this.subscribe||(this.provided=!0,this.callback&&this.callback(t,s)),this.unsubscribe=s},this.host=t,void 0!==s.context){const t=s;this.context=t.context,this.callback=t.callback,this.subscribe=t.subscribe??!1}else this.context=s,this.callback=i,this.subscribe=h??!1;this.host.addController(this)}hostConnected(){this.dispatchRequest()}hostDisconnected(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=void 0)}dispatchRequest(){this.host.dispatchEvent(new t(this.context,this.t,this.subscribe))}}export{s as ContextConsumer};
//# sourceMappingURL=context-consumer.js.map

@@ -9,3 +9,3 @@ /**

*/
export declare type Context<KeyType, ValueType> = KeyType & {
export type Context<KeyType, ValueType> = KeyType & {
__context__: ValueType;

@@ -16,7 +16,7 @@ };

*/
export declare type ContextKey<KeyType, ValueType> = Context<KeyType, ValueType>;
export type ContextKey<KeyType, ValueType> = Context<KeyType, ValueType>;
/**
* A helper type which can extract a Context value type from a Context type
*/
export declare type ContextType<Key extends Context<unknown, unknown>> = Key extends Context<unknown, infer ValueType> ? ValueType : never;
export type ContextType<Key extends Context<unknown, unknown>> = Key extends Context<unknown, infer ValueType> ? ValueType : never;
/**

@@ -23,0 +23,0 @@ * Creates a typed Context.

@@ -6,3 +6,3 @@ import{decorateProperty as t}from"@lit/reactive-element/decorators/base.js";import{ContextProvider as e}from"../controllers/context-provider.js";

* SPDX-License-Identifier: BSD-3-Clause
*/function o({context:o}){return t({finisher:(t,n)=>{const r=new WeakMap;t.addInitializer((t=>{r.set(t,new e(t,{context:o}))}));const i=Object.getOwnPropertyDescriptor(t.prototype,n),c=null==i?void 0:i.set,s={...i,set:function(t){var e;null===(e=r.get(this))||void 0===e||e.setValue(t),c&&c.call(this,t)}};Object.defineProperty(t.prototype,n,s)}})}export{o as provide};
*/function o({context:o}){return t({finisher:(t,n)=>{const r=new WeakMap;t.addInitializer((t=>{r.set(t,new e(t,{context:o}))}));const c=Object.getOwnPropertyDescriptor(t.prototype,n),i=c?.set,s={...c,set:function(t){r.get(this)?.setValue(t),i&&i.call(this,t)}};Object.defineProperty(t.prototype,n,s)}})}export{o as provide};
//# sourceMappingURL=provide.js.map

@@ -6,3 +6,3 @@ /**

*/
class t{constructor(t){this.callbacks=new Map,this.updateObservers=()=>{for(const[t,s]of this.callbacks)t(this.o,s)},void 0!==t&&(this.value=t)}get value(){return this.o}set value(t){this.setValue(t)}setValue(t,s=!1){const i=s||!Object.is(t,this.o);this.o=t,i&&this.updateObservers()}addCallback(t,s){s&&(this.callbacks.has(t)||this.callbacks.set(t,(()=>{this.callbacks.delete(t)}))),t(this.value)}clearCallbacks(){this.callbacks.clear()}}export{t as ValueNotifier};
class t{get value(){return this.o}set value(t){this.setValue(t)}setValue(t,s=!1){const i=s||!Object.is(t,this.o);this.o=t,i&&this.updateObservers()}constructor(t){this.callbacks=new Map,this.updateObservers=()=>{for(const[t,s]of this.callbacks)t(this.o,s)},void 0!==t&&(this.value=t)}addCallback(t,s){s&&(this.callbacks.has(t)||this.callbacks.set(t,(()=>{this.callbacks.delete(t)}))),t(this.value)}clearCallbacks(){this.callbacks.clear()}}export{t as ValueNotifier};
//# sourceMappingURL=value-notifier.js.map
{
"name": "@lit-labs/context",
"version": "0.3.1",
"version": "0.3.2-pre.0",
"description": "Helpers and controllers for using Context protocol",

@@ -63,2 +63,3 @@ "license": "BSD-3-Clause",

"files": [
"tsconfig.json",
"src/**/*.ts"

@@ -147,8 +148,9 @@ ],

"dependencies": {
"@lit/reactive-element": "^1.5.0",
"lit": "^2.7.0"
"@lit/reactive-element": "^2.0.0-pre.0",
"lit": "^3.0.0-pre.0"
},
"devDependencies": {
"@lit-internal/scripts": "^1.0.0",
"@lit-labs/testing": "^0.2.0",
"@esm-bundle/chai": "^4.3.4-fix.0",
"@lit-internal/scripts": "^1.0.1-pre.0",
"@lit-labs/testing": "^0.2.2-pre.0",
"@types/trusted-types": "^2.0.2"

@@ -155,0 +157,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc