parent
8540c39c31
commit
9dc097d52a
@ -1,20 +1,27 @@
|
||||
import watch from './watch.js'
|
||||
import { renderVariables } from './template.js'
|
||||
|
||||
const state = watch(
|
||||
{
|
||||
name: 'matt',
|
||||
friend: {
|
||||
name: 'bob'
|
||||
},
|
||||
stuff: ['bag', 123, true]
|
||||
},
|
||||
() => {
|
||||
console.log(state);
|
||||
}
|
||||
)
|
||||
const template = `hi {{name}}`
|
||||
|
||||
console.log(state);
|
||||
state.name = 'Matthew'
|
||||
state.friend.name = 'Bilbo'
|
||||
state.stuff[0] = 'fun'
|
||||
state.stuff.push('weeee')
|
||||
const result = renderVariables(template, { name:'matt'})
|
||||
|
||||
console.log(result);
|
||||
|
||||
//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