
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
A paper-thin, 100% typesafe Redux for babies
# Using Yarn:
yarn add babydux
# Or, using NPM:
npm install babydux --save
import { connect, createStore } from 'babydux'
// If you're using Babydux with TypeScript, declare your store's types.
type Store = {
today: Date
users: string[]
}
// Create a store with an initial value.
let store = createStore<Store>({
today: new Date,
users: []
})
export let withStore = connect(store)
Be sure to define a key for each value in your model, even if the value is initially undefined
.
import { withStore } from './store'
// Update the component when `today` changes
let MyComponent = withStore('today')(({ store }) =>
<div>
Hello! Today is {store.get('today')}
<button onClick={() => store.set('today')(new Date)}>Update Date</button>
</div>
)
That's all there is to it.
Though Babydux automatically updates your model for you, it also lets you listen on and react to model updates (similarly to how vanilla Redux lets you subscribe to Actions). Babydux subscriptions are full Rx observables, so you have fine control over how you react to a change:
store
.on('today')
.filter(() => _.getTime() % 2 === 0) // only even timestamps
.debounce(100)
.subscribe(_ => console.log('Date changed', _))
Instead of updating your React component when anything on the model changed, you subscribe just to specific properties on your model. Let's modify our React example to only update when today
changes:
let MyComponent = withStore('today')(
({ store }) => ...
)
Everything is the same as before, I just added 'today'
as an argument to the function returned by connect
.
Partially apply the connect
function to yield a convenient withStore
function:
let withStore = connect(store)
Or, partially apply the set
function to yield a convenient setter:
let setUsers = store.set('users')
setUsers(['amy'])
setUsers(['amy', 'bob'])
If you create your store with withLogger
higher order store, all model updates (which key was updated, previous value, and new value) will be logged to the console.
To enable the logger, import withLogger
and wrap your store with it:
import { createStore, withLogger } from 'babydux'
let store = withLogger(createStore<Store>({...}, true))
And logs look like this:
Babydux is easy to modify with plugins (also called "higher order stores"). Just define a function that takes a store as an argument and returns a store, adding listeners along the way. For convenience, Babydux supports 2 types of listeners for plugins:
import { createStore, Plugin } from 'babydux'
let withLocalStorage: Plugin = store => {
// Listen on an event
store.onAll().subscribe(_ =>
console.log('something changed!', _)
)
// Listen on an event (fires before the model is updated)
store.beforeAll().subscribe(({ key, previousValue, value}) =>
localStorage.set(key, value)
)
}
Babydux also supports .on()
and .before()
, but because a plugin doesn't know what Actions will be bound to it, these are generally unsafe to use.
Goal #1 is total type-safety.
Getting, setting, reading, and listening on model updates is 100% type-safe: use a key that isn't defined in your model or set a key to the wrong type, and you'll get a compile-time error. And connected components are just as type-safe.
Goal #2 is letting you write as little boilerplate as possible.
Babydux is like Redux, but reducers are already baked-in. Babydux automatically creates an action and a reducer for each key on your state, so you don't have to write tedious boilerplate. Babydux still emits Actions under the hood (which you can listen on to produce effects), but gives you an incredibly simple get
/set
API that covers most use cases.
If you're using Babydux with the provided React connector, Babydux will update your React component any time a reducer fires (just like React-Redux). You can optionally filter on specific state keys that you care about for more targeted updates.
yarn test
MIT
FAQs
A paper-thin, 100% typesafe Redux for babies
We found that babydux 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.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.