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.19 to 0.0.20

test/subscribe/switch/any.js

1

lib/subscribe/any.js

@@ -1,2 +0,1 @@

'use strict'
const { property } = require('./property')

@@ -3,0 +2,0 @@ const { getKeys } = require('../keys')

var property, any, root, parent, $switch
const diff = (t, subs, cb, tree, removed) => {
// if (diff(t, subs, cb, branch, tree, void 0, branch.$c)) {
const diff = (t, subs, cb, tree, removed, composite) => {
var changed
for (let key in subs) {
if (key !== 'val' && key !== 'props' && key !== '_' && key !== '$blockRemove') {
if (parse(key, t, subs, cb, tree, removed)) {
changed = true
if (composite) {
for (let key in composite) {
if (key in tree) {
let branch = tree[key]
let c = branch.$c
if (c) {
if (key === '$any') {
for (let k in c) {
let y = branch[k].$c
if (property(k, t, subs.$any, cb, branch, removed, y)) {
changed = true
}
}
} else if (parse(key, t, subs, cb, tree, removed, c)) {
changed = true
}
} else {
if (parse(key, t, subs, cb, tree, removed)) {
changed = true
}
}
}
}
} else {
for (let key in subs) {
if (key !== 'val' && key !== 'props' && key !== '_' && key !== '$blockRemove') {
if (parse(key, t, subs, cb, tree, removed, composite)) {
changed = true
}
}
}
}

@@ -15,3 +42,3 @@ return changed

const parse = (key, t, subs, cb, tree, removed) => {
const parse = (key, t, subs, cb, tree, removed, composite) => {
if (key === 'root') {

@@ -23,8 +50,8 @@ return root(t, subs.root, cb, tree, removed)

if (key === '$any') {
return any(t, subs.$any, cb, tree, removed)
return any(t, subs.$any, cb, tree, removed, composite)
} else if (key.indexOf('$switch') === 0) {
return $switch(key, t, subs, cb, tree, removed)
return $switch(key, t, subs, cb, tree, removed, composite)
}
} else {
return property(key, t, subs[key], cb, tree, removed)
return property(key, t, subs[key], cb, tree, removed, composite)
}

@@ -31,0 +58,0 @@ }

@@ -1,6 +0,6 @@

const { diff, parse } = require('../diff')
const { diff } = require('../diff')
const remove = require('./remove')
const { getOrigin } = require('../../get')
const update = (key, t, subs, cb, tree) => {
const update = (key, t, subs, cb, tree, c) => {
var branch = tree[key]

@@ -14,3 +14,3 @@ var changed

if (subs.val) { cb(t, 'new', subs, branch) }
diff(t, subs, cb, branch)
diff(t, subs, cb, branch, void 0, c)
changed = true

@@ -21,6 +21,7 @@ } else if (branch.$ !== stamp || branch.$t !== t) {

if (subs.val === true) { cb(t, 'update', subs, branch) }
diff(t, subs, cb, branch)
diff(t, subs, cb, branch, void 0, c)
changed = true
} else if (branch.$c) {
if (composite(t, subs, cb, branch, tree)) {
// console.log('????', branch.$c)
if (diff(t, subs, cb, branch, void 0, branch.$c)) {
changed = true // cover this

@@ -37,25 +38,30 @@ }

const composite = (t, subs, cb, branch, tree) => {
var changed
const c = branch.$c
if (tree._key === '$any') {
for (let key in c) {
// in this parse it can only do root / parent and composite nothing else
// extra argument that says trough composite makes it a lot more solid
// or key is also a possiblity
if (key in branch && parse(key, t, subs, cb, branch)) {
changed = true // cover this
}
}
} else {
for (let key in c) {
if (key in branch && key in subs && parse(key, t, subs, cb, branch)) {
changed = true // cover it!
}
}
}
return changed
}
// const composite = (t, subs, cb, branch, tree, prev) => {
// var changed
// const c = branch.$c
const property = (key, t, subs, cb, tree, removed) => {
// // just diff make composite diff and normal one
// // can just use diff for this...
// if (tree._key === '$any') {
// // you can do this in div now...
// for (let key in c) {
// // in this parse it can only do root / parent and composite nothing else
// // extra argument that says trough composite makes it a lot more solid
// // or key is also a possiblity
// if (key in branch && parse(key, t, subs, cb, branch, void 0, c)) {
// changed = true // cover this
// }
// }
// } else {
// for (let key in c) {
// if (key in branch && key in subs && parse(key, t, subs, cb, branch, void 0, c)) {
// changed = true // cover it!
// }
// }
// }
// return changed
// }
const property = (key, t, subs, cb, tree, removed, composite) => {
var changed

@@ -74,3 +80,4 @@ if (removed) {

cb,
tree
tree,
composite
)

@@ -77,0 +84,0 @@ }

@@ -7,14 +7,14 @@ const { diff } = require('./diff')

const driverChange = (key, tkey, t, subs, cb, tree, removed) => {
const driverChange = (key, tkey, t, subs, cb, tree, removed, composite) => {
const branch = tree[key]
if (diff(t, subs, driver, branch, removed)) {
return body(tkey, t, subs, cb, tree, removed, subs.val, false)
if (diff(t, subs, driver, branch, removed, composite)) {
return body(tkey, t, subs, cb, tree, removed, subs.val, false, composite)
}
}
const $switch = (key, t, subs, cb, tree, removed) => {
const $switch = (key, t, subs, cb, tree, removed, composite) => {
var $switch = subs[key]
if (!$switch) {
let tkey = key.slice(0, -1) // this means from composite
driverChange(key, tkey, t, subs[tkey], cb, tree, removed)
driverChange(key, tkey, t, subs[tkey], cb, tree, removed, composite)
} else {

@@ -25,14 +25,14 @@ if ($switch.val) {

if (driverBranch) {
if (diff(t, $switch, driver, driverBranch, removed)) {
return body(key, t, subs, cb, tree, removed, $switch.val, true)
if (diff(t, $switch, driver, driverBranch, removed, composite)) {
return body(key, t, subs, cb, tree, removed, $switch.val, true, composite)
} else {
const branch = tree[key]
if (branch) { update(key, t, branch.$subs, cb, tree, removed) }
if (branch) { update(key, t, branch.$subs, cb, tree, removed, composite) }
}
} else if (!driverBranch) {
create(dKey, t, $switch, driver, tree)
return body(key, t, subs, cb, tree, removed, $switch.val, true)
create(dKey, t, $switch, driver, tree, composite)
return body(key, t, subs, cb, tree, removed, $switch.val, true, composite)
}
} else {
return body(key, t, subs, cb, tree, removed, $switch, true)
return body(key, t, subs, cb, tree, removed, $switch, true, composite)
}

@@ -42,8 +42,8 @@ }

const create = (key, t, subs, cb, tree) => {
const create = (key, t, subs, cb, tree, composite) => {
const branch = tree[key] = { _p: tree, _key: key, $subs: subs }
return diff(t, subs, cb, branch)
return diff(t, subs, cb, branch, void 0, composite)
}
const body = (key, t, subs, cb, tree, removed, $switch, diffit) => {
const body = (key, t, subs, cb, tree, removed, $switch, diffit, composite) => {
var result

@@ -59,3 +59,3 @@ if (!removed && t) { result = $switch(t, subs, tree, key) }

if (!branch) {
update(key, t, result, cb, tree)
update(key, t, result, cb, tree, void 0, composite)
tree[key].$subs = result

@@ -65,7 +65,7 @@ return true

remove(branch.$subs, cb, branch)
update(key, t, result, cb, tree)
update(key, t, result, cb, tree, void 0, composite)
tree[key].$subs = result
return true
} else if (diffit) {
return update(key, t, result, cb, tree, removed)
return update(key, t, result, cb, tree, removed, composite)
}

@@ -72,0 +72,0 @@ }

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

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

@@ -13,5 +13,5 @@ # brisky-struct

- Fast reactive state management. Inspired by virtual-dom tree-diffing algorithms and merkle-trees
- Powerfull query syntax
- Powerful query syntax
- Fast emitters
- Async helpers, work with generators, promises and iterators
- Low footprint (6kb gzipped)

@@ -333,6 +333,6 @@ const perf = require('brisky-performance')

s.subscribe(
{ $any: { x: { root: { query: true } } } },
{ collection: { $any: { x: { root: { query: true } } } } },
() => {}
)
for (let i = 0; i < n * 100; i++) {
for (let i = 0; i < n * 10; i++) {
s.query.set(i)

@@ -351,9 +351,63 @@ }

s.subscribe(
{ $any: { x: { root: { query: true } } } },
{ collection: { $any: { x: { $root: { query: { val: true } } } } } },
() => {}
)
for (let i = 0; i < n; i++) {
s.query.set(i)
}
}, `root subscription n = ${(n * 10 * 100 / 1e3) | 0}k`, 10)
perf(() => {
const arr = []
let i = 100
while (i--) {
arr.push({ x: true })
}
const s = struct({
collection: arr,
query: 'hello'
})
s.subscribe(
{
collection: {
$any: {
$switch: state => {
return state.key === '1' &&
{ x: { root: { query: { val: true } } } }
}
}
}
},
() => {}
)
for (let i = 0; i < n * 100; i++) {
s.query.set(i)
}
}, `root subscription n = ${(n * 100 / 1e3) | 0}k`, 10)
}, () => {
const arr = []
let i = 100
while (i--) {
arr.push({ x: true })
}
const s = new State({
collection: arr,
query: 'hello'
})
s.subscribe(
{ collection: {
$any: {
$test: {
exec: state => state.key === '10',
$pass: {
x: { $root: { query: { val: true } } }
}
}
}
} },
() => {}
)
for (let i = 0; i < n * 10; i++) {
s.query.set(i)
}
}, `root + test subscription n = ${(n * 100 / 1e3) | 0}k`, 10)

@@ -360,0 +414,0 @@ perf(() => {

@@ -39,85 +39,85 @@ 'use strict'

test('subscription - composite - root - nested', t => {
const subs = {
a: {
root: { b: { c: { d: { val: true } } } }
}
}
const s = subsTest(t, { a: true }, subs)
s(
'set b/c/d',
[ { path: 'b/c/d', type: 'new' } ],
{ b: { c: { d: 'its d!' } } }
)
t.end()
})
// test('subscription - composite - root - nested', t => {
// const subs = {
// a: {
// root: { b: { c: { d: { val: true } } } }
// }
// }
// const s = subsTest(t, { a: true }, subs)
// s(
// 'set b/c/d',
// [ { path: 'b/c/d', type: 'new' } ],
// { b: { c: { d: 'its d!' } } }
// )
// t.end()
// })
test('subscription - composite - root - double', t => {
const subs = {
a: {
root: {
b: {
c: {
root: { c: { val: true } }
}
}
}
}
}
const s = subsTest(t, { a: true }, subs)
s(
'set c',
[ { path: 'c', type: 'new' } ],
{ b: { c: {} }, c: 'hello c!' }
)
t.end()
})
// test('subscription - composite - root - double', t => {
// const subs = {
// a: {
// root: {
// b: {
// c: {
// root: { c: { val: true } }
// }
// }
// }
// }
// }
// const s = subsTest(t, { a: true }, subs)
// s(
// 'set c',
// [ { path: 'c', type: 'new' } ],
// { b: { c: {} }, c: 'hello c!' }
// )
// t.end()
// })
test('subscription - composite - root - multiple', t => {
const subs = {
a: {
root: {
c: { val: true },
b: { val: true }
}
}
}
const s = subsTest(t, { a: true }, subs)
s('initial subscription', [])
s('set b', [ { path: 'b', type: 'new' } ], { b: 'hello b!' })
s('set c', [ { path: 'c', type: 'new' } ], { c: 'hello c!' })
s('update c', [ { path: 'c', type: 'update' } ], { c: 'hello c2!' })
s('remove c', [ { path: 'c', type: 'remove' } ], { c: null })
t.end()
})
// test('subscription - composite - root - multiple', t => {
// const subs = {
// a: {
// root: {
// c: { val: true },
// b: { val: true }
// }
// }
// }
// const s = subsTest(t, { a: true }, subs)
// s('initial subscription', [])
// s('set b', [ { path: 'b', type: 'new' } ], { b: 'hello b!' })
// s('set c', [ { path: 'c', type: 'new' } ], { c: 'hello c!' })
// s('update c', [ { path: 'c', type: 'update' } ], { c: 'hello c2!' })
// s('remove c', [ { path: 'c', type: 'remove' } ], { c: null })
// t.end()
// })
test('subscription - composite - root - remove combined with normal', t => {
const subs = {
b: { val: true },
a: { root: { b: { val: true } } }
}
const s = subsTest(t, { b: true, a: true }, subs)
s('remove b', [
{ path: 'b', type: 'remove' },
{ path: 'b', type: 'remove' }
], { b: null })
t.end()
})
// test('subscription - composite - root - remove combined with normal', t => {
// const subs = {
// b: { val: true },
// a: { root: { b: { val: true } } }
// }
// const s = subsTest(t, { b: true, a: true }, subs)
// s('remove b', [
// { path: 'b', type: 'remove' },
// { path: 'b', type: 'remove' }
// ], { b: null })
// t.end()
// })
test('subscription - composite - root - property', t => {
const subs = {
b: { val: 1 },
a: {
root: { b: { val: 1 } }
}
}
const s = subsTest(t, {}, subs)
s('create b', [ { path: 'b', type: 'new' } ], { b: true })
s('create a', [ { path: 'b', type: 'new' } ], { a: true })
s('update b', [], { b: 'update!' })
s('remove b', [
{ path: 'b', type: 'remove' },
{ path: 'b', type: 'remove' }
], { b: null })
t.end()
})
// test('subscription - composite - root - property', t => {
// const subs = {
// b: { val: 1 },
// a: {
// root: { b: { val: 1 } }
// }
// }
// const s = subsTest(t, {}, subs)
// s('create b', [ { path: 'b', type: 'new' } ], { b: true })
// s('create a', [ { path: 'b', type: 'new' } ], { a: true })
// s('update b', [], { b: 'update!' })
// s('remove b', [
// { path: 'b', type: 'remove' },
// { path: 'b', type: 'remove' }
// ], { b: null })
// t.end()
// })
require('./basic')
require('./references')
require('./parent')
require('./mixed')
require('./any')
require('./mixed')
require('./basic')
require('./any')
require('./composite')
require('./method')
require('./references')
require('./composite')
require('./switch')
require('./basic')
require('./remove')
require('./any')
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