New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

brisky-struct

Package Overview
Dependencies
Maintainers
1
Versions
397
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

brisky-struct - npm Package Compare versions

Comparing version 0.0.32 to 0.0.33

1

lib/struct/types.js

@@ -18,3 +18,2 @@ const { create } = require('../manipulate')

t.type = val
// console.log('when not of the same type remove it', t.key, val)
}

@@ -21,0 +20,0 @@

36

lib/subscribe/any.js

@@ -5,2 +5,3 @@ const { update: updateProperty } = require('./property')

const { getOrigin } = require('../get')
const { diff } = require('./diff')

@@ -70,3 +71,7 @@ const inherits = (key, t, index) => {

if (subs.$keys) {
keys = subs.$keys(keys, t)
if (subs.$keys.val) {
keys = subs.$keys.val(keys, t)
} else {
keys = subs.$keys(keys, t)
}
}

@@ -96,2 +101,8 @@ if (keys) {

}
if (subs.$keys && subs.$keys.val) {
const dKey = '$keys' + key
const dBranch = branch[dKey] = { _p: branch, _key: dKey }
diff(t, subs.$keys, stub, dBranch)
}
}

@@ -107,14 +118,18 @@

const stub = () => {}
const composite = (key, t, subs, cb, branch, removed, c) => {
var changed
if (subs.$keys) {
const keys = subs.$keys(parseKeys(t), t)
if (keys.length !== branch.$keys.length) {
update(key, keys, t, subs, cb, branch)
changed = true
const keys = branch.$keys
if (subs.$keys && subs.$keys.val) {
const dKey = '$keys' + key
if (c[dKey] && diff(t, subs.$keys, stub, branch[dKey])) {
any(key, t, subs, cb, branch._p, removed)
} else {
for (let k in c) {
let y = branch.$keys[k].$c
let tt = keys && getOrigin(t, keys[k])
if (updateProperty(k, tt, subs, cb, branch.$keys, y, branch)) {
let target = keys[k]
if (
k !== dKey &&
updateProperty(k, target.$t, subs, cb, keys, target.$c, branch)
) {
changed = true

@@ -125,3 +140,2 @@ }

} else {
const keys = branch.$keys
for (let k in c) {

@@ -150,3 +164,3 @@ let target = keys[k]

}
} else { // some keys are removed
} else {
for (let i = 0; i < len2; i++) {

@@ -153,0 +167,0 @@ let key = keys[i]

@@ -11,11 +11,27 @@ const { diff } = require('../diff')

const parent = tree._p
if (tree.$c) { composite(parent, key) }
if (parent.$keys) {
parent.$keys.splice(key, 1)
// way too slow remove _key
let i = parent.$keys.length - key
while (i--) {
parent.$keys[i]._key = i
const len = parent.$keys.length
let i = len
if (tree.$c) {
while (i-- > key) {
parent.$keys[i]._key = i
// if (parent.$keys[i].$c) {
// // if (!parent.$c[i]) {
// // console.log('RE-ADD') // may need this later
// // }
// } else if (parent.$c[i]) {
// composite(parent, i)
// }
}
if (parent.$c[len]) {
composite(parent, len)
}
} else {
while (i-- > key) {
parent.$keys[i]._key = i
}
}
} else {
if (tree.$c) { composite(parent, key) }
delete parent[key]

@@ -22,0 +38,0 @@ }

{
"name": "brisky-struct",
"description": "An observable data structure",
"version": "0.0.32",
"version": "0.0.33",
"main": "lib/index.js",

@@ -6,0 +6,0 @@ "scripts": {

@@ -39,11 +39,7 @@ const test = require('tape')

// [ { path: 'fields/b/title', type: 'update' }, { path: 'fields/b/title', type: 'remove' }, { path: 'fields/c/title', type: 'remove' } ]
// [ { path: 'fields/b/title', type: 'update' }, { path: 'fields/b/title', type: 'remove' }, { path: 'fields/c/title', type: 'remove' }
const r = s(
s(
'remove field in a collection',
[
{ path: 'fields/b/title', type: 'update' }, // this is new ofc
{ path: 'fields/b/title', type: 'remove' }, // seems weird that you dont get a but it makes all the sense
{ path: 'fields/b/title', type: 'update' },
{ path: 'fields/b/title', type: 'remove' },
{ path: 'fields/c/title', type: 'remove' }

@@ -53,3 +49,2 @@ ],

)
console.log(r.state.fields.keys())

@@ -96,4 +91,2 @@ s(

// console.log(result.state.keys())
s(

@@ -110,4 +103,2 @@ 'remove field',

console.log(result.state.keys())
s(

@@ -119,4 +110,2 @@ 'remove fields',

{ path: 'd', type: 'remove' }
// if you want to get info about the previous one need to cache do may be nice to do.... this is jsut weird
// were removing b and c
],

@@ -126,6 +115,2 @@ { a: 'hello', b: null, c: null }

// this one is wrong... needs to clean up better
console.log(result.tree.$any.$keys.length, result.tree.$any.$keys.map(val => val.$t.path()))
console.log(result.state.keys())
const struct = result.state

@@ -137,4 +122,2 @@ struct.set({ start: 'start' }, false)

// reshuffle needs to fire updates!
// need to see 2 new but new for things that are allrdy rendered thats re-order
s(

@@ -149,3 +132,3 @@ 'add field and reorder keys',

)
// shuffle array (re-sort)
t.end()

@@ -159,4 +142,2 @@ })

{ $any: { val: 'property' } }
// hmm this is not so nice need to fire for switch as well...
// when switch in any its becomes to weird
)

@@ -190,3 +171,3 @@

[
{ path: 'b', type: 'remove' } // ok so this seems strange but it aint
{ path: 'b', type: 'remove' }
],

@@ -242,3 +223,3 @@ { a: null }

const r = s('initial subscription', [
s('initial subscription', [
{ path: 'fields/0', type: 'new' },

@@ -258,4 +239,2 @@ { path: 'fields/1', type: 'new' }

)
console.log(r.state.fields.keys())
t.end()

@@ -262,0 +241,0 @@ })

@@ -63,5 +63,5 @@ const test = require('tape')

collection: {
a: { rating: 6 },
b: { rating: 4 },
c: { rating: 10 }
a: true,
b: true,
c: true
}

@@ -73,29 +73,44 @@ })

$any: {
$keys: (keys, s) => keys.filter(val => s.root().get([ 'target', 'compute' ]) === val ||
s.root().get([ 'target', 'compute' ]) === '*'),
$keys: {
val: (keys, s) =>
keys.filter(val => s.root().get([ 'target', 'compute' ]) === val ||
s.root().get([ 'target', 'compute' ]) === '*'),
root: { target: true }
},
val: true,
root: { target: true }
root: {
hello: true
}
}
}
}, (val, type) => {
results.push(type === 'remove' ? '-' + val.key : val.key)
})
t.same(results, [ 'a', 'target' ], 'initial subscription')
}, (v, t) => results
.push(t === 'remove' ? '-' + v.key : t === 'new' ? '+' + v.key : v.key)
)
t.same(results, [ '+a' ], 'initial subscription')
results = []
s.target.set('b')
t.same(results, [ 'b', 'target' ], 'remove a, shift c')
t.same(results, [ 'b' ], 'replace a')
results = []
s.target.set('*')
t.same(results, [ 'a', 'target', 'b', 'target', 'c', 'target' ], 'add all')
t.same(results, [ 'a', '+b', '+c' ], 'add all')
results = []
s.target.set('b')
t.same(results, [ 'b', 'target', '-b', '-target', '-c', '-target' ], 'use b') // this breaks everything now
t.same(results, [ 'b', '-b', '-c' ], 'use b') // this breaks everything now
// results = []
// s.target.set('nothing') // this crashes...
// t.same(results, [ 'b', 'target', '-b', '-target', '-c', '-target' ], 'use b') // this breaks everything now
results = []
s.target.set('nothing') // this crashes...
t.same(results, [ '-b' ], 'use nothing') // this breaks everything now
results = []
s.target.set('*')
t.same(results, [ '+a', '+b', '+c' ], 'add all')
results = []
s.set({ hello: 'yes' })
t.same(results, [ '+hello', 'a', '+hello', 'b', '+hello', 'c' ], 'update hello')
t.end()
})

@@ -107,1 +107,48 @@ const test = require('tape')

})
test('subscription - $switch - any - filter', t => {
const s = subsTest(t, {
list: [ { bla: { rating: 3 } }, { bla: { rating: 1 } }, { bla: { rating: 2 } }, { bla: { rating: 4 } } ],
thing: 1,
unicorn: 'unicorn'
}, {
list: {
$any: {
$keys: (keys, s) => {
return keys.filter(val => s[val].bla.rating.compute() < 10)
},
bla: {
$switch: {
val: (t, subs, tree) => {
if (t.rating.compute() > 2) {
return { root: { unicorn: { val: true } } }
} else {
return { val: true }
}
},
rating: { val: true }
}
}
}
}
})
s('initial subscription', [
{ path: 'unicorn', type: 'new' },
{ path: 'list/1/bla', type: 'new' },
{ path: 'list/2/bla', type: 'new' },
{ path: 'unicorn', type: 'new' }
])
s('remove 0', [
{ path: 'unicorn', type: 'remove' },
{ path: 'list/1/bla', type: 'new' },
{ path: 'list/1/bla', type: 'remove' },
{ path: 'list/2/bla', type: 'new' },
{ path: 'list/2/bla', type: 'remove' },
{ path: 'unicorn', type: 'new' },
{ path: 'unicorn', type: 'remove' }
], { list: { 0: { bla: { rating: 10 } } } })
t.end()
})
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