@ctx-core/store
Advanced tools
Comparing version 5.0.36 to 6.0.0
76
lib.js
@@ -1,2 +0,74 @@ | ||
require = require('esm')(module) | ||
module.exports = require('./lib.mjs') | ||
// TODO: Use when https://github.com/sveltejs/svelte-extras/issues/20 is resolved | ||
//import {observe} from 'svelte-extras' | ||
import { setDeep, observe, observeDeep, observeMany } from 'svelte-extras/dist/svelte-extras.es.js' | ||
import { mixin, clone } from '@ctx-core/object/lib.js' | ||
import { flatten } from '@ctx-core/array/lib.js' | ||
import { Store } from 'svelte/store.js' | ||
import { log } from '@ctx-core/logger/lib.js' | ||
export { _ctx } from './lib.nodep.js' | ||
const logPrefix = '@ctx-core/store/lib.js' | ||
export function _store() { | ||
const store = new Store(...arguments) | ||
mixin(store, { | ||
observe, | ||
observeDeep, | ||
observeMany, | ||
setDeep, | ||
clone__get() { | ||
return clone(this.get(), ...arguments) | ||
}, | ||
get store() {return this.get().store}, | ||
get g() {return this.get()} | ||
}) | ||
store.observe = observe | ||
return store | ||
} | ||
export function _mixin__store(name, init) { | ||
return async function mixin__store(store) { | ||
if (store[name]) return store | ||
store[name] = { | ||
store, | ||
name, | ||
} | ||
await init(...arguments) | ||
return store | ||
} | ||
} | ||
/** | ||
* Adds computed properties onto a svelte store | ||
* @param store | ||
* @param definitions | ||
* @returns {*} | ||
* @example | ||
* compute(store, { | ||
computed1: [ | ||
'prop1', | ||
'prop2', | ||
(prop1, prop2) => prop1 / prop2 | ||
], | ||
computed2: [ | ||
'computed1', | ||
'prop3', | ||
(computed1, prop3) => computed1 * prop3 | ||
] | ||
}) | ||
*/ | ||
export function compute(store, definitions) { | ||
for (let key in definitions) { | ||
const definition = definitions[key] | ||
const dependencies = flatten(definition.slice(0, definition.length - 1)) | ||
const fn = definition[definition.length - 1] | ||
if (typeof fn !== 'function') { | ||
throw `compute ${key} must have a function as the last element` | ||
} | ||
store.compute(key, dependencies, fn) | ||
} | ||
return store | ||
} | ||
export function ensure__store(ctx, store) { | ||
log(`${logPrefix}|ensure__store`) | ||
if (ctx.store) return ctx | ||
store = store || _store(ctx) | ||
ctx.store = store | ||
return ctx | ||
} |
{ | ||
"name": "@ctx-core/store", | ||
"version": "5.0.36", | ||
"version": "6.0.0", | ||
"description": "ctx-core store", | ||
@@ -24,10 +24,9 @@ "main": "lib.js", | ||
"dependencies": { | ||
"@ctx-core/array": "^7.12.0", | ||
"@ctx-core/logger": "^2.2.12", | ||
"@ctx-core/object": "^2.6.0", | ||
"esm": "^3.0.84", | ||
"@ctx-core/array": "^8.0.0", | ||
"@ctx-core/logger": "^3.0.0", | ||
"@ctx-core/object": "^3.0.0", | ||
"svelte": "^2.16.0", | ||
"svelte-extras": "^2.0.2" | ||
}, | ||
"gitHead": "ef8c06c1b6e6183cce5b0836c59761cce170a6e9" | ||
"gitHead": "7d0d73495e67101da1ad8aeb87a7b9918b4689c1" | ||
} |
5
2767
+ Added@ctx-core/array@8.3.0(transitive)
+ Added@ctx-core/function@5.6.16.0.0(transitive)
+ Added@ctx-core/logger@3.1.28(transitive)
+ Added@ctx-core/object@3.3.0(transitive)
+ Added@ctx-core/set@4.0.0(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedsupports-color@7.2.0(transitive)
- Removedesm@^3.0.84
- Removed@ctx-core/array@7.12.0(transitive)
- Removed@ctx-core/function@4.2.0(transitive)
- Removed@ctx-core/logger@2.2.12(transitive)
- Removed@ctx-core/object@2.6.0(transitive)
- Removed@ctx-core/set@3.0.2(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedesm@3.2.25(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedsupports-color@5.5.0(transitive)
Updated@ctx-core/array@^8.0.0
Updated@ctx-core/logger@^3.0.0
Updated@ctx-core/object@^3.0.0