Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
businessman
Advanced tools
Multi-thread State Management by the Worker API.
Outline
import { worker } from 'businessman'
worker.registerStore( {
type: 'counter',
state: 0,
mutations: {
increment: ( store, num ) => {
store.state += num
}
},
actions: {
increment: ( store, num = 1 ) => {
store.commit( 'increment', num )
}
}
} )
Type is a string that is the identity of the store. This needs to be unique.
type: 'counter'
Save the state of the store. Any type can be used for the state.
state: 0
Change the state. After that, the new state is automatically notified to the main thread.
The first argument of the mutation is the store instance.
For example, to update the state by changing the store.state
.
increment: ( store, num ) => {
store.state += num
}
ATTENTION
Execute the mutation. Asynchronous processing can be placed on the action.
The first argument of the action is the store instance.
For example, call store.commit()
to execute the mutation.
increment: ( store, num = 1 ) => {
store.commit( 'increment', num )
}
Call worker.start()
to start a worker.
worker.start()
When added to the source of the Create Store as shown earlier, it becomes as follows.
import { worker } from 'businessman'
worker.registerStore( {
type: 'counter',
state: 0,
mutations: {
increment: ( store, num ) => {
store.state += num
}
},
actions: {
increment: ( store, num = 1 ) => {
store.commit( 'increment', num )
}
}
} )
worker.start()
Install workers and start state management.
import { install } from 'businessman'
install( '/path/to/worker.js' )
ATTENTION
import { dispatch, subscribe } from 'businessman'
dispatch( 'counter', 'increment', 1 )
subscribe( 'counter', ( state ) => {
console.log( state ) // 1
} )
Dispatch / Subscribe is also available in Store style.
counter.dispatch( 'increment', 1 )
counter.subscribe( ( state ) => {
console.log( state )
} )
The store style is available after the store in the worker has been created for the client. It can be obtained by subscribing CREATE_CLIENT_STORE
.
let counter
subscribe( 'CREATE_CLIENT_STORE', ( stores ) => {
console.log( stores ) // { counter: { dispatch: function () {...}, subscribe: function () {...}, unsubscribe: function () {...}, getState: function () {...} } }
counter = stores.counter
} )
You can stop / delete subscribe.
import { unsubscribe } from 'businessman'
unsubscribe( 'counter' ) // Delete all listeners subscribing to the store
unsubscribe( 'counter', listener ) // Delete one listener
For store style ...
counter.unsubscribe()
counter.unsubscribe( listener )
In Businessman getState()
is also executed asynchronously.
counter.getState()
.then( ( state ) => {
console.log( state )
} )
See Board on GitLab.
You can feel free to join anytime!
FAQs
Powerful, Secure, Multi-threaded Flux Patterns.
The npm package businessman receives a total of 1 weekly downloads. As such, businessman popularity was classified as not popular.
We found that businessman demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.