Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
renderjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Romain Courteaud
renderjs
Commits
f69c54b2
Commit
f69c54b2
authored
Apr 14, 2014
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Acquired method get the child scope as parameter.
parent
ddaeb274
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
5 deletions
+60
-5
renderjs.js
renderjs.js
+16
-4
test/renderjs_test.js
test/renderjs_test.js
+44
-1
No files found.
renderjs.js
View file @
f69c54b2
...
...
@@ -89,8 +89,18 @@
/////////////////////////////////////////////////////////////////
// RenderJSGadget.declareAcquiredMethod
/////////////////////////////////////////////////////////////////
function
acquire
(
method_name
,
argument_list
)
{
var
gadget
=
this
;
function
acquire
(
child_gadget
,
method_name
,
argument_list
)
{
var
gadget
=
this
,
key
,
gadget_scope
;
for
(
key
in
gadget
.
__sub_gadget_dict
)
{
if
(
gadget
.
__sub_gadget_dict
.
hasOwnProperty
(
key
))
{
if
(
gadget
.
__sub_gadget_dict
[
key
]
===
child_gadget
)
{
gadget_scope
=
key
;
}
}
}
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
// Do not specify default __acquired_method_dict on prototype
...
...
@@ -98,7 +108,8 @@
// allowPublicAcquiredMethod for example)
var
aq_dict
=
gadget
.
__acquired_method_dict
||
{};
if
(
aq_dict
.
hasOwnProperty
(
method_name
))
{
return
aq_dict
[
method_name
].
apply
(
gadget
,
[
argument_list
]);
return
aq_dict
[
method_name
].
apply
(
gadget
,
[
argument_list
,
gadget_scope
]);
}
throw
new
renderJS
.
AcquisitionError
(
"
aq_dynamic is not defined
"
);
})
...
...
@@ -365,7 +376,8 @@
var
i
;
// Define __aq_parent to reach parent gadget
gadget_instance
.
__aq_parent
=
function
(
method_name
,
argument_list
)
{
return
acquire
.
apply
(
parent_gadget
,
[
method_name
,
argument_list
]);
return
acquire
.
apply
(
parent_gadget
,
[
gadget_instance
,
method_name
,
argument_list
]);
};
// Drop the current loading klass info used by selector
gadget_loading_klass
=
undefined
;
...
...
test/renderjs_test.js
View file @
f69c54b2
...
...
@@ -2184,12 +2184,13 @@
gadget
.
__acquired_method_dict
=
{};
gadget
.
__acquired_method_dict
[
original_method_name
]
=
function
(
argument_list
)
{
function
(
argument_list
,
child_scope
)
{
aq_dynamic_called
=
true
;
equal
(
this
,
gadget
,
"
Context should be kept
"
);
deepEqual
(
argument_list
,
original_argument_list
,
"
Argument list should be kept
"
);
equal
(
child_scope
,
undefined
,
"
No child scope if unknown
"
);
return
"
FOO
"
;
};
...
...
@@ -2217,6 +2218,48 @@
});
});
test
(
'
__aq_parent propagate child_scope to acquired_method
'
,
function
()
{
var
gadget
=
new
RenderJSGadget
(),
aq_dynamic_called
=
false
,
original_method_name
=
"
foo
"
,
original_argument_list
=
[
"
foobar
"
,
"
barfoo
"
],
html_url
=
'
http://example.org/files/qunittest/test353.html
'
;
gadget
.
__acquired_method_dict
=
{};
gadget
.
__sub_gadget_dict
=
{};
gadget
.
__acquired_method_dict
[
original_method_name
]
=
function
(
argument_list
,
child_scope
)
{
aq_dynamic_called
=
true
;
equal
(
this
,
gadget
,
"
Context should be kept
"
);
deepEqual
(
argument_list
,
original_argument_list
,
"
Argument list should be kept
"
);
equal
(
child_scope
,
"
bar
"
,
"
Child scope should be provided
"
);
};
this
.
server
.
respondWith
(
"
GET
"
,
html_url
,
[
200
,
{
"
Content-Type
"
:
"
text/html
"
},
"
<html><body></body></html>
"
]);
stop
();
gadget
.
declareGadget
(
html_url
,
{
scope
:
"
bar
"
})
.
then
(
function
(
new_gadget
)
{
return
new_gadget
.
__aq_parent
(
original_method_name
,
original_argument_list
);
})
.
then
(
function
(
result
)
{
equal
(
aq_dynamic_called
,
true
);
})
.
fail
(
function
(
e
)
{
ok
(
false
,
e
);
})
.
always
(
function
()
{
start
();
});
});
test
(
'
__aq_parent fails if aquired_method throws an error
'
,
function
()
{
var
gadget
=
new
RenderJSGadget
(),
original_error
=
new
Error
(
"
Custom error for the test
"
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment