-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
574503d
commit 17db22a
Showing
3 changed files
with
58 additions
and
84 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
34 changes: 34 additions & 0 deletions
34
src/generators/dom/visitors/attributes/binding/getSetter.js
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,34 @@ | ||
import deindent from '../../../../../utils/deindent.js'; | ||
|
||
export default function getSetter ({ current, name, context, attribute, dependencies, snippet, value }) { | ||
if ( name in current.contexts ) { | ||
const prop = dependencies[0]; | ||
const tail = attribute.value.type === 'MemberExpression' ? getTailSnippet( attribute.value ) : ''; | ||
|
||
return deindent` | ||
var list = this.${context}.${current.listNames[ name ]}; | ||
var index = this.${context}.${current.indexNames[ name ]}; | ||
list[index]${tail} = ${value}; | ||
component._set({ ${prop}: component.get( '${prop}' ) }); | ||
`; | ||
} | ||
|
||
if ( attribute.value.type === 'MemberExpression' ) { | ||
return deindent` | ||
var ${name} = component.get( '${name}' ); | ||
${snippet} = ${value}; | ||
component._set({ ${name}: ${name} }); | ||
`; | ||
} | ||
|
||
return `component._set({ ${name}: ${value} });`; | ||
} | ||
|
||
function getTailSnippet ( node ) { | ||
const end = node.end; | ||
while ( node.type === 'MemberExpression' ) node = node.object; | ||
const start = node.end; | ||
|
||
return `[✂${start}-${end}✂]`; | ||
} |