
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.
Using Muxjs is easy to track the app state. What's state and it's tansition? When look back your codes, often find some logic are described as below:
if this condition and this other condition are met, then this value should be 'x'.
Here, vars of condition are state, and condition is transition, so 'x' is the transposition's result. Muxjs give the way to subscribe vars's changs and transition's result 'x''s changes.
Let's look at the diagram of an example case of an stateful application:
Left
of diagram is a view-controller with 5 state (circle) and 3 transition (rhombus).
Right
of disgram is an UI Page with 4 parts, each part depend on one state or transition.
If we can subscribe all changes of state and transition, so we can bind specified DOM opertion when state/transition change,
finally it implement the data to DOM binding , event can do more stuff for a completed MVVM framework such as Zect.
It's usefull, right?
browser:
<script src="dist/mux.js"></script>
node.js:
npm install muxjs --save
Mux(options)
:bookmark: API Reference Navigation
It is a constructor function that allows you to create Mux instance.options
see: Instance Options.
var author = new Mux({
props: {
name: 'firstName lastName'
},
computed: {
firstName: {
deps: ['name'],
fn: function () {
return this.name.split(' ')[0]
}
}
}
})
assert.equal(author.firstName, 'firstName')
Mux.extend([options])
Function
Class:bookmark: API Reference Navigation
Create a subclass of the base Mux constructor. options
see: Instance Options.
Class can instance with param propsObj
which will set values to those observered properties of the instance.
var Person = Mux.extend({
props: {
profession: 'programer',
name: ''
}
})
var author = new Person({
name: 'switer'
})
assert.equal(author.profession, 'programer')
assert.equal(author.name, 'switer')
Mux.config([conf])
:bookmark: API Reference Navigation
Global configure. Currently supported configurations:
* warn Boolean
if value is false
, don't show any warning log. Default is true
Mux.config({
warn: false // no warning log
})
Mux.emitter([context])
Object
binding "this" to context
for event callbacks.:bookmark: API Reference Navigation
Create a emitter instance.
var emitter = Mux.emitter()
emitter.on('change:name', function (name) {
// do something
}) // subscribe
emitter.off('change:name') // unsubscribe
emitter.emitter('change:name', 'switer') // publish message
props
Function
| Object
:bookmark: API Reference Navigation
Return the initial observed property object for this mux instance.Recommend to using function which return a object if you don't want to share props option's object in each instance:
var Person = Mux.extend({
props: function () {
return {
name: 'mux'
}
}
})
assert.equal((new person).name, 'mux')
props option could be an object:
var Person = new Mux({
props: {
name: 'mux'
}
})
assert.equal((new person).name, 'mux')
computed
Object
Array
property dependencies.
Restricton: deps
's item could be keyPath (contain .
and []
, such as: "post.comments[0]").Function
Compute function , using as a getterBoolean
Whether the computed property enumerable or not:bookmark: API Reference Navigation
Computed properties definition option. "fn"
will be called if one of dependencies has change, then will emit a change event if "fn"
returns result has change.
var mux = new Mux({
props: {
items: [1,2,3]
},
computed: {
count: {
deps: ['items'],
fn: function () {
return this.items.length
}
}
}
})
assert.equal(mux.cout, 3)
Watch computed property changes:
mux.$watch('count', function (next, pre) {
assert.equal(next, 3)
assert.equal(next, 4)
})
mux.items.push(4)
assert.equal(mux.count, 4)
emitter
EventEmitter
:bookmark: API Reference Navigation
Use custom emitter instance.
var emitter = Mux.emitter()
emitter.on('change:name', function (next) {
next // --> switer
})
var mux = new Mux({
emitter: emitter,
props: {
name: ''
}
})
mux.name = 'switer'
$set([keyPath, value] | props)
String
property path , such as: "items[0].name"Object
[optional] data structure as below:{ "propertyName | keyPath": propertyValue }
:bookmark: API Reference Navigation
Set value to property by property's keyPath or propertyName, which could trigger change event when value change or value is an object reference (instanceof Object). Notice: PropertyName shouldn't a keyPath (name string without contains "[", "]", "." )
var list = new Mux({
items: [{name: '1'}]
})
list.$set('items[0].name', '')
$get(propname)
String
only propertyname not keyPath (without contains "[", "]", "."):bookmark: API Reference Navigation
Get property value. It's equal to using "." or "[]" to access value except computed properties.
var mux = new Mux({
props: {
replyUsers: [{
author: 'switer'
}]
}
})
assert.equal(mux.$get('replyUses[0].author', 'switer'))
Notice: Using "." or "[]" to access computed property's value will get a cached result, so you can use "$get()" to recompute the property's value whithout cache.
// define a computed property which use to get the first user of replyUsers
mux.$computed(firstReplyUser, ['replyUsers'], function () {
return this.replyUsers[0].author
})
var users = [{
author: 'switer'
}]
mux.$set('replyUsers', users)
user[0].author = 'guankaishe' // modify selft
assert.equal(post.firstReplyUser, 'switer'))
assert.equal(post.$get('firstReplyUser'), 'guankaishe'))
$add([propname [, defaultValue]] | propnameArray | propsObj)
String
Array
Object
:bookmark: API Reference Navigation
Define an observerable property or multiple properties.
mux.$add('name', 'switer')
// or
mux.$add(['name']) // without default value
// or
mux.$add({ 'name': 'switer' })
$computed([propname, deps, get, set, enum] | computedPropsObj)
String
property nameArray
Property's dependenciesFunction
Getter functionFunction
Setter functionBoolean
whether the computed property enumerable or notObject
:bookmark: API Reference Navigation
Define a computed property. deps and fn is necessary. If one of deps is observable of the instance, emitter a change event after define. computedPropsObj is using to define multiple computed properties in once, each key of computedPropsObj is property's name and value is a object contains "deps", "fn". Usage as below:
// before define computed
assert.equal(mux.commentCount, undefined)
mux.$computed('commentCount', ['comments'], function () {
return this.comments.length
})
// after define computed
assert.equal(mux.commentCount, 1)
$watch([propname, ] callback)
String
[optional]Function
Function
unwatch handler:bookmark: API Reference Navigation
Subscribe property or computed property changes of the Mux instance.
var unwatch = mux.$watch('title', function (nextValue, preValue) {
// callback when title has change
})
unwatch() // cancel subscribe
if propname is not present, will watch all property or computed property changes:
mux.$watch(function (propname, nextValue, preValue) {
// callback when title has change
})
$unwatch([propname, ] [callback])
String
[optional]Function
[optional]:bookmark: API Reference Navigation
Unsubscribe property or computed property changes of the Mux instance.
// subscribe
mux.$watch('name', handler)
// unsubscribe
mux.$unwatch('name', handler)
// unsubscribe all of specified propertyname
mux.$unwatch('name')
// unsubscribe all of the Mux instance
mux.$unwatch()
$props( )
Object
:bookmark: API Reference Navigation
Return all properties of the instance. Properties do not contain computed properties(Only observed properties).
var mux = Mux({ props: { name: 'Muxjs' } })
mux.$props() // --> {name: 'Muxjs'}
$emitter(emitter)
:bookmark: API Reference Navigation
Reset emitter of the mux instance. If arguments is empty, return the emitter of the instance.
var mux = Mux()
var em = Mux.emitter()
mux.$emitter(em)
var muxEmitter = mux.$emitter() // equal to em
$destroy()
:bookmark: API Reference Navigation
Destroy the instance, remove all listener of the internal emiter of the instance, free all props references.
$destroyed()
:bookmark: API Reference Navigation
Whether the instance is destroyed or not.
MIT
FAQs
Modeling app states with muxjs.
We found that muxjs 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.