Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
stated-bean
Advanced tools
A light but scalable
view-model
library with react hooks.
# yarn
yarn add stated-bean
# npm
npm i stated-bean
GitHub Pages: Integration with injection-js
import { useBean } from 'stated-bean';
const CounterModel = {
count: 0,
decrement() {
this.count--;
},
increment() {
this.count++;
},
};
function CounterDisplay() {
const counter = useBean(() => CounterModel);
return (
<div>
<button onClick={counter.decrement}>-</button>
<span>{counter.count}</span>
<button onClick={counter.increment}>+</button>
</div>
);
}
function App() {
return (
<StatedBeanProvider>
<CounterDisplay />
</StatedBeanProvider>
);
}
import { StatedBean, Stated useBean } from 'stated-bean';
@StatedBean()
class CounterModel {
@Stated()
count = 0;
increment() {
this.count++;
}
decrement() {
this.count--;
}
}
function CounterDisplay() {
const counter = useBean(CounterModel);
return (
// ...
);
}
The named bean singleton bean can be resolved via useInject
with the special name.
@StatedBean('SpecialName')
class NamedBean {}
@StatedBean({ singleton: true })
class SingletonBean {}
useBean
const model = useBean(CounterModel, { name: 'SpecialName' });
The beans was stored in the StatedBeanContainer
witch be created by the StatedBeanProvider
and bind to the React context.
useInject
will find the named bean from the container or it's parent container.
@StatedBean({ singleton: true })
class UserModel {
@Stated()
user = { name: 'jack' };
}
function App() {
return (
<StatedBeanProvider providers={[UserModel]}>
<UserDisplay />
</StatedBeanProvider>
);
}
function UserDisplay() {
const model = useInject(UserModel);
return model.user.name;
}
@StatedBean()
class InputModel implements InitializingBean {
@Props('initialValue')
@Stated()
value: number;
@ObservableProps()
value$: BehaviorSubject<number>;
afterProvided() {
this.value$.subscribe(v => {
this.value = v;
});
}
}
function Input(props: InputProps) {
const model = useBean(InputModel, { props });
return (
// input component
);
}
@StatedBean()
class SearchModel {
@Effect()
search() {
return fetchUsers();
}
}
const UserTable() {
const model = useBean(SearchModel);
const { loading, error } = useObserveEffect(model, "search");
if (loading) {
return <Loading />;
}
return (
// ...user table
);
}
StatedBean
Signature: @StatedBean(name?: string | symbol): ClassDecorator
Indicates that an annotated class is a StatedBean
. The name
may indicate a suggestion for the bean name. Its default value is Class.name
.
Stated
Signature: @Stated(): PropertyDecorator
Indicates that an annotated property is Stated
. Its reassignment will be observed and notified to the container.
AfterProvided
Signature: @AfterProvided(): MethodDecorator
The AfterProvided
decorator is used on a method that needs to be executed after the StatedBean
be instanced to perform any initialization.
Effect
Signature: @Effect(name?: string | symbol): MethodDecorator
The Effect
decorator is used on a method that can get the execution state by useObserveEffect
.
Props
and ObservableProps
Signature: @Props(name?: string): PropertyDecorator
@ObservableProps(name?: string): PropertyDecorator
The Props
decorator is used on a property that can sync the value from props.
The ObservableProps
decorator is used on a BehaviorSubject
property. You can subscribe the next new props value.
useBean
Signature: useBean<T>(typeOrSupplier: ClassType<T> | () => T, name?: string | symbol): T
The useBean
will create an instance of the stated bean with a new StatedBeanContainer
and listen for its data changes to trigger the re-rendering of the current component.
useInject
Signature: useInject<T>(type: ClassType<T>, option: UseStatedBeanOption<T> = {}): T
The useInject
will get the instance of the stated bean from the StatedBeanContainer
in the context and listen for its data changes to trigger the re-rendering of the current component.
UseStatedBeanOption
option = {
name: string | symbol; // get/create the instance with special name
dependentFields: Array<string | symbol>; // do re-render when the special property changed
};
useObserveEffect
Signature: useObserveEffect(bean: StatedBeanType, name: string | symbol): EffectAction
observe the execution state of the method which with @Effect
.
<StatedBeanProvider {...props: StatedBeanProviderProps} />
The StatedBeanProvider
is responsible for creating an instance of the stated bean and dispatching an event after data changes.
StatedBeanProviderProps
interface StatedBeanProviderProps {
types?: ClassType[];
beans?: Array<StatedBeanType<unknown>>;
beanProvider?: BeanProvider;
application?: StatedBeanApplication;
}
FAQs
A light but scalable state management library with react hooks
The npm package stated-bean receives a total of 0 weekly downloads. As such, stated-bean popularity was classified as not popular.
We found that stated-bean demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.