added _bb.get/setContext to clientApi - for MD components

This commit is contained in:
Michael Shanks 2020-02-24 16:41:03 +00:00
parent 829eea4189
commit cb79302b1a
7 changed files with 21 additions and 11 deletions

View File

@ -3,6 +3,7 @@ import { setState, setStateFromBinding } from "./setState"
import { trimSlash } from "../common/trimSlash"
import { isBound } from "./parseBinding"
import { attachChildren } from "../render/attachChildren"
import { getContext, setContext } from "./getSetContext"
export const bbFactory = ({
store,
@ -60,6 +61,8 @@ export const bbFactory = ({
setState: (path, value) => setState(store, path, value),
getStateOrValue: (prop, currentContext) =>
getStateOrValue(getCurrentState(), prop, currentContext),
getContext: getContext(treeNode),
setContext: setContext(treeNode),
store: store,
relativeUrl,
api,

View File

@ -0,0 +1,11 @@
export const setContext = treeNode => (key, value) =>
(treeNode.context[key] = value)
export const getContext = treeNode => key => {
if (treeNode.context && treeNode.context[key] !== undefined)
return treeNode.context[key]
if (!treeNode.context.$parent) return
return getContext(treeNode.parentNode)(key)
}

View File

@ -10,6 +10,7 @@
export let onLoad
const cb = new ClassBuilder("data-table")
_bb.setContext("BBMD:data-table:cb", cb)
let datatable = null
let instance = null

View File

@ -1,10 +1,9 @@
<script>
import { getContext } from "svelte"
import ClassBuilder from "../ClassBuilder.js"
export let _bb
const cb = new ClassBuilder("data-table")
const cb = _bb.getContext("BBMD:data-table:cb")
let tbody

View File

@ -1,12 +1,11 @@
<script>
import { getContext } from "svelte"
import ClassBuilder from "../ClassBuilder.js"
export let isHeader = false
export let numeric = false
export let _bb
const cb = new ClassBuilder("data-table")
const cb = _bb.getContext("BBMD:data-table:cb")
let elementName = isHeader ? "header-cell" : "cell"
let modifiers = { numeric }

View File

@ -1,10 +1,8 @@
<script>
import ClassBuilder from "../ClassBuilder.js"
export let _bb
const cb = new ClassBuilder("data-table")
const cb = _bb.getContext("BBMD:data-table:cb")
let thead

View File

@ -1,7 +1,6 @@
<script>
import { getContext } from "svelte";
import ClassBuilder from "../ClassBuilder.js"
export let onSelect = () => {};
export let isHeader = false;
@ -10,7 +9,7 @@
let row = null;
let selected = false;
const cb = new ClassBuilder("data-table")
const cb = _bb.getContext("BBMD:data-table:cb")
let elementName = isHeader ? "header-row" : "row";
let modifiers = {};