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 dce21f7fbe
commit f0dbfa15bf
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 { trimSlash } from "../common/trimSlash"
import { isBound } from "./parseBinding" import { isBound } from "./parseBinding"
import { attachChildren } from "../render/attachChildren" import { attachChildren } from "../render/attachChildren"
import { getContext, setContext } from "./getSetContext"
export const bbFactory = ({ export const bbFactory = ({
store, store,
@ -60,6 +61,8 @@ export const bbFactory = ({
setState: (path, value) => setState(store, path, value), setState: (path, value) => setState(store, path, value),
getStateOrValue: (prop, currentContext) => getStateOrValue: (prop, currentContext) =>
getStateOrValue(getCurrentState(), prop, currentContext), getStateOrValue(getCurrentState(), prop, currentContext),
getContext: getContext(treeNode),
setContext: setContext(treeNode),
store: store, store: store,
relativeUrl, relativeUrl,
api, 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 export let onLoad
const cb = new ClassBuilder("data-table") const cb = new ClassBuilder("data-table")
_bb.setContext("BBMD:data-table:cb", cb)
let datatable = null let datatable = null
let instance = null let instance = null

View File

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

View File

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

View File

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

View File

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