parent
8540c39c31
commit
9dc097d52a
@ -1,20 +1,27 @@
|
|||||||
import watch from './watch.js'
|
import watch from './watch.js'
|
||||||
|
import { renderVariables } from './template.js'
|
||||||
|
|
||||||
const state = watch(
|
const template = `hi {{name}}`
|
||||||
{
|
|
||||||
name: 'matt',
|
|
||||||
friend: {
|
|
||||||
name: 'bob'
|
|
||||||
},
|
|
||||||
stuff: ['bag', 123, true]
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
console.log(state);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
console.log(state);
|
const result = renderVariables(template, { name:'matt'})
|
||||||
state.name = 'Matthew'
|
|
||||||
state.friend.name = 'Bilbo'
|
console.log(result);
|
||||||
state.stuff[0] = 'fun'
|
|
||||||
state.stuff.push('weeee')
|
//const state = watch(
|
||||||
|
//{
|
||||||
|
//name: 'matt',
|
||||||
|
//friend: {
|
||||||
|
//name: 'bob'
|
||||||
|
//},
|
||||||
|
//stuff: ['bag', 123, true]
|
||||||
|
//},
|
||||||
|
//() => {
|
||||||
|
//console.log(state);
|
||||||
|
//}
|
||||||
|
//)
|
||||||
|
|
||||||
|
//console.log(state);
|
||||||
|
//state.name = 'Matthew'
|
||||||
|
//state.friend.name = 'Bilbo'
|
||||||
|
//state.stuff[0] = 'fun'
|
||||||
|
//state.stuff.push('weeee')
|
||||||
|
|||||||
@ -0,0 +1,7 @@
|
|||||||
|
const renderVariables = (template, data) => {
|
||||||
|
return template.replace(/\{\{(\w+)\}\}/g, (match, templateVar) => {
|
||||||
|
return data[templateVar]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export { renderVariables }
|
||||||
Loading…
Reference in new issue