diff --git a/index.js b/index.js index 65e5dab..cbca76c 100644 --- a/index.js +++ b/index.js @@ -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') diff --git a/template.js b/template.js new file mode 100644 index 0000000..fc5d35f --- /dev/null +++ b/template.js @@ -0,0 +1,7 @@ +const renderVariables = (template, data) => { + return template.replace(/\{\{(\w+)\}\}/g, (match, templateVar) => { + return data[templateVar] + }); +} + +export { renderVariables }