Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Operators): add string template tag
- Loading branch information
1 parent
b039f2b
commit 7d18eaa
Showing
5 changed files
with
44 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
/* eslint-env mocha */ | ||
import Controller from '../Controller' | ||
import assert from 'assert' | ||
import {input, set, state} from './' | ||
import {input, string} from './' | ||
|
||
describe('operator.input', () => { | ||
it('should read value from input', () => { | ||
const controller = new Controller({ | ||
state: { | ||
foo: 'bar' | ||
}, | ||
signals: { | ||
test: [ | ||
set(state`foo`, input`foo`) | ||
(context) => { | ||
assert.deepEqual(string`foo.${input`foo`}`(context).toValue(), 'foo.bar') | ||
} | ||
] | ||
} | ||
}) | ||
controller.getSignal('test')({foo: 'baz'}) | ||
assert.deepEqual(controller.getState(), {foo: 'baz'}) | ||
controller.getSignal('test')({foo: 'bar'}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import populatePath from './helpers/populatePath' | ||
|
||
export default function string (strings, ...values) { | ||
return (context) => { | ||
const target = 'string' | ||
const path = populatePath(context, strings, values) | ||
|
||
return { | ||
target, | ||
path, | ||
toValue () { | ||
return path | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* eslint-env mocha */ | ||
import Controller from '../Controller' | ||
import assert from 'assert' | ||
import {input, string} from './' | ||
|
||
describe('operator.string', () => { | ||
it('should build path', () => { | ||
const controller = new Controller({ | ||
signals: { | ||
test: [ | ||
(context) => { | ||
assert.deepEqual(string`foo.${input`ref`}`(context).toValue(), 'foo.bar') | ||
} | ||
] | ||
} | ||
}) | ||
controller.getSignal('test')({ref: 'bar'}) | ||
}) | ||
}) |