Skip to content

Commit

Permalink
feat: add support for the context api
Browse files Browse the repository at this point in the history
The context API is similar to VueJS provide/inject API https://v3.vuejs.org/guide/component-provide-inject.html
  • Loading branch information
thetutlage committed Jan 14, 2021
1 parent c775f0e commit bf98b5d
Show file tree
Hide file tree
Showing 91 changed files with 671 additions and 94 deletions.
2 changes: 1 addition & 1 deletion async-fixtures/components-advanced-props/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compileComponent("components-advanced-props/button")(template, template.getComponentState({ class: 'mb-4 px-4', id: 'foo-bar', title: 'Click me' }, { main: function () { return "" } }, { filename: $filename, line: $lineNumber, col: 0 }));
out += await template.compileComponent("components-advanced-props/button")(template, template.getComponentState({ class: 'mb-4 px-4', id: 'foo-bar', title: 'Click me' }, { $context: Object.assign({}, $context), main: function () { return "" } }, { filename: $filename, line: $lineNumber, col: 0 }), $context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
Expand Down
2 changes: 1 addition & 1 deletion async-fixtures/components-falsy-args/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compileComponent("components-falsy-args/alert")(template, template.getComponentState({ index: 0 }, { main: function () { return "" } }, { filename: $filename, line: $lineNumber, col: 0 }));
out += await template.compileComponent("components-falsy-args/alert")(template, template.getComponentState({ index: 0 }, { $context: Object.assign({}, $context), main: function () { return "" } }, { filename: $filename, line: $lineNumber, col: 0 }), $context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
Expand Down
2 changes: 1 addition & 1 deletion async-fixtures/components-isolated-state/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compileComponent("components-isolated-state/alert")(template, template.getComponentState({}, { main: function () { return "" } }, { filename: $filename, line: $lineNumber, col: 0 }));
out += await template.compileComponent("components-isolated-state/alert")(template, template.getComponentState({}, { $context: Object.assign({}, $context), main: function () { return "" } }, { filename: $filename, line: $lineNumber, col: 0 }), $context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
Expand Down
6 changes: 3 additions & 3 deletions async-fixtures/components-named-slots/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compileComponent("components-named-slots/alert")(template, template.getComponentState({}, { main: async function () {
out += await template.compileComponent("components-named-slots/alert")(template, template.getComponentState({}, { $context: Object.assign({}, $context), main: async function () { const $context = this.$context;
let slot_main = "";
try {
slot_main += " Hello ";
Expand All @@ -18,15 +18,15 @@ slot_main += " line 2";
template.reThrow(error, $filename, $lineNumber);
}
return slot_main;
}, "heading": async function () {
}, "heading": async function () { const $context = this.$context;
let slot_1 = "";
try {
slot_1 += " This is title";
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
return slot_1;
} }, { filename: $filename, line: $lineNumber, col: 0 }));
} }, { filename: $filename, line: $lineNumber, col: 0 }), $context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
Expand Down
4 changes: 2 additions & 2 deletions async-fixtures/components-partials/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compileComponent("components-partials/alert")(template, template.getComponentState({ username: "virk" }, { main: async function () {
out += await template.compileComponent("components-partials/alert")(template, template.getComponentState({ username: "virk" }, { $context: Object.assign({}, $context), main: async function () { const $context = this.$context;
let slot_main = "";
try {
slot_main += " Hello ";
Expand All @@ -12,7 +12,7 @@ slot_main += `${template.escape(state.username || "Guest")}`;
template.reThrow(error, $filename, $lineNumber);
}
return slot_main;
} }, { filename: $filename, line: $lineNumber, col: 0 }));
} }, { filename: $filename, line: $lineNumber, col: 0 }), $context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
Expand Down
4 changes: 2 additions & 2 deletions async-fixtures/components-props/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compileComponent("components-props/alert")(template, template.getComponentState({ "title": "H1" }, { main: async function () {
out += await template.compileComponent("components-props/alert")(template, template.getComponentState({ "title": "H1" }, { $context: Object.assign({}, $context), main: async function () { const $context = this.$context;
let slot_main = "";
try {
slot_main += "Hello world";
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
return slot_main;
} }, { filename: $filename, line: $lineNumber, col: 0 }));
} }, { filename: $filename, line: $lineNumber, col: 0 }), $context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
Expand Down
4 changes: 2 additions & 2 deletions async-fixtures/components-slot-props/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compileComponent("components-slot-props/alert")(template, template.getComponentState({}, { main: function () { return "" }, "title": async function (user) {
out += await template.compileComponent("components-slot-props/alert")(template, template.getComponentState({}, { $context: Object.assign({}, $context), main: function () { return "" }, "title": async function (user) { const $context = this.$context;
let slot_1 = "";
try {
slot_1 += " Hello ";
Expand All @@ -16,7 +16,7 @@ slot_1 += `${template.escape(state.username)}`;
template.reThrow(error, $filename, $lineNumber);
}
return slot_1;
} }, { filename: $filename, line: $lineNumber, col: 0 }));
} }, { filename: $filename, line: $lineNumber, col: 0 }), $context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
Expand Down
6 changes: 3 additions & 3 deletions async-fixtures/components-slots-partials/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compileComponent("components-slots-partials/alert")(template, template.getComponentState({}, { main: async function () {
out += await template.compileComponent("components-slots-partials/alert")(template, template.getComponentState({}, { $context: Object.assign({}, $context), main: async function () { const $context = this.$context;
let slot_main = "";
try {
$lineNumber = 2;
slot_main += await template.compilePartial("components-slots-partials/partial")(template,state);
slot_main += await template.compilePartial("components-slots-partials/partial")(template,state,$context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
return slot_main;
} }, { filename: $filename, line: $lineNumber, col: 0 }));
} }, { filename: $filename, line: $lineNumber, col: 0 }), $context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
Expand Down
4 changes: 2 additions & 2 deletions async-fixtures/components-state/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compileComponent("components-state/alert")(template, template.getComponentState({}, { main: async function () {
out += await template.compileComponent("components-state/alert")(template, template.getComponentState({}, { $context: Object.assign({}, $context), main: async function () { const $context = this.$context;
let slot_main = "";
try {
slot_main += " Hello ";
Expand All @@ -12,7 +12,7 @@ slot_main += `${template.escape(state.username)}`;
template.reThrow(error, $filename, $lineNumber);
}
return slot_main;
} }, { filename: $filename, line: $lineNumber, col: 0 }));
} }, { filename: $filename, line: $lineNumber, col: 0 }), $context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
Expand Down
4 changes: 2 additions & 2 deletions async-fixtures/components/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compileComponent("components/alert")(template, template.getComponentState({}, { main: async function () {
out += await template.compileComponent("components/alert")(template, template.getComponentState({}, { $context: Object.assign({}, $context), main: async function () { const $context = this.$context;
let slot_main = "";
try {
slot_main += " Hello world";
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
return slot_main;
} }, { filename: $filename, line: $lineNumber, col: 0 }));
} }, { filename: $filename, line: $lineNumber, col: 0 }), $context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
Expand Down
2 changes: 1 addition & 1 deletion async-fixtures/each-tag-include/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ try {
await template.loopAsync(state.users, async function (user,index) {
out += "\n";
$lineNumber = 2;
out += await template.compilePartial('each-tag-include/user',"user","index")(template,state,user,index);
out += await template.compilePartial('each-tag-include/user',"user","index")(template,state,$context,user,index);
});
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
Expand Down
2 changes: 1 addition & 1 deletion async-fixtures/include-conditionals/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compilePartial(`include-conditionals/${state.username === "virk" ? "virk.edge" : "guest.edge"}`)(template,state);
out += await template.compilePartial(`include-conditionals/${state.username === "virk" ? "virk.edge" : "guest.edge"}`)(template,state,$context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
Expand Down
2 changes: 1 addition & 1 deletion async-fixtures/include-identifier/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compilePartial(state.partial)(template,state);
out += await template.compilePartial(state.partial)(template,state,$context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
Expand Down
2 changes: 1 addition & 1 deletion async-fixtures/include-if-identifier/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
if (state.username === 'virk') {
out += await template.compilePartial(state.partial)(template,state);
out += await template.compilePartial(state.partial)(template,state,$context);
}
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
Expand Down
2 changes: 1 addition & 1 deletion async-fixtures/include-if-literal/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
if (state.username === 'virk') {
out += await template.compilePartial("include-if-literal/partial")(template,state);
out += await template.compilePartial("include-if-literal/partial")(template,state,$context);
}
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
Expand Down
2 changes: 1 addition & 1 deletion async-fixtures/include-literal/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compilePartial("include-literal/partial")(template,state);
out += await template.compilePartial("include-literal/partial")(template,state,$context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
Expand Down
2 changes: 1 addition & 1 deletion async-fixtures/include-nested-shared-locals/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let $filename = "{{__dirname}}index.edge";
try {
let username = 'virk';
$lineNumber = 2;
out += await template.compilePartial("include-nested-shared-locals/partial","username")(template,state,username);
out += await template.compilePartial("include-nested-shared-locals/partial","username")(template,state,$context,username);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
Expand Down
2 changes: 1 addition & 1 deletion async-fixtures/include-nested/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compilePartial("include-nested/partial")(template,state);
out += await template.compilePartial("include-nested/partial")(template,state,$context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
Expand Down
2 changes: 1 addition & 1 deletion async-fixtures/include-shared-ctx/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compilePartial("include-shared-ctx/partial")(template,state);
out += await template.compilePartial("include-shared-ctx/partial")(template,state,$context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
Expand Down
18 changes: 18 additions & 0 deletions async-fixtures/inject-function-calls/compiled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compileComponent('inject-function-calls/modal')(template, template.getComponentState({}, { $context: Object.assign({}, $context), main: async function () { const $context = this.$context;
let slot_main = "";
try {
$lineNumber = 2;
slot_main += `${template.escape($context.foo())}`;
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
return slot_main;
} }, { filename: $filename, line: $lineNumber, col: 0 }), $context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
return out;
3 changes: 3 additions & 0 deletions async-fixtures/inject-function-calls/index.edge
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@component('inject-function-calls/modal')
{{ $context.foo() }}
@end
1 change: 1 addition & 0 deletions async-fixtures/inject-function-calls/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions async-fixtures/inject-function-calls/index.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foobar
3 changes: 3 additions & 0 deletions async-fixtures/inject-function-calls/modal.edge
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@set('foo', 'foobar')
@inject({ foo: () => foo })
{{{ await $slots.main() }}}
18 changes: 18 additions & 0 deletions async-fixtures/inject-identifier/compiled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compileComponent('inject-identifier/modal')(template, template.getComponentState({}, { $context: Object.assign({}, $context), main: async function () { const $context = this.$context;
let slot_main = "";
try {
$lineNumber = 2;
slot_main += `${template.escape($context.foo)}`;
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
return slot_main;
} }, { filename: $filename, line: $lineNumber, col: 0 }), $context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
return out;
3 changes: 3 additions & 0 deletions async-fixtures/inject-identifier/index.edge
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@component('inject-identifier/modal')
{{ $context.foo }}
@end
1 change: 1 addition & 0 deletions async-fixtures/inject-identifier/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions async-fixtures/inject-identifier/index.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bar
3 changes: 3 additions & 0 deletions async-fixtures/inject-identifier/modal.edge
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@set('foo', { foo: 'bar' })
@inject(foo)
{{{ await $slots.main() }}}
18 changes: 18 additions & 0 deletions async-fixtures/inject-object-expression/compiled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compileComponent('inject-object-expression/modal')(template, template.getComponentState({}, { $context: Object.assign({}, $context), main: async function () { const $context = this.$context;
let slot_main = "";
try {
$lineNumber = 2;
slot_main += `${template.escape($context.foo)}`;
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
return slot_main;
} }, { filename: $filename, line: $lineNumber, col: 0 }), $context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
return out;
3 changes: 3 additions & 0 deletions async-fixtures/inject-object-expression/index.edge
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@component('inject-object-expression/modal')
{{ $context.foo }}
@end
1 change: 1 addition & 0 deletions async-fixtures/inject-object-expression/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions async-fixtures/inject-object-expression/index.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bar
2 changes: 2 additions & 0 deletions async-fixtures/inject-object-expression/modal.edge
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@inject({ foo: 'bar' })
{{{ await $slots.main() }}}
18 changes: 18 additions & 0 deletions async-fixtures/inject-object-with-references/compiled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let out = "";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
out += await template.compileComponent('inject-object-with-references/modal')(template, template.getComponentState({}, { $context: Object.assign({}, $context), main: async function () { const $context = this.$context;
let slot_main = "";
try {
$lineNumber = 2;
slot_main += `${template.escape($context.foo)}`;
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
return slot_main;
} }, { filename: $filename, line: $lineNumber, col: 0 }), $context);
} catch (error) {
template.reThrow(error, $filename, $lineNumber);
}
return out;
3 changes: 3 additions & 0 deletions async-fixtures/inject-object-with-references/index.edge
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@component('inject-object-with-references/modal')
{{ $context.foo }}
@end
1 change: 1 addition & 0 deletions async-fixtures/inject-object-with-references/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions async-fixtures/inject-object-with-references/index.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foobar
3 changes: 3 additions & 0 deletions async-fixtures/inject-object-with-references/modal.edge
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@set('foo', 'foobar')
@inject({ foo })
{{{ await $slots.main() }}}
Loading

0 comments on commit bf98b5d

Please sign in to comment.