@@ -23,17 +23,12 @@ def livewire_message(request, component_name):
23
23
def get_id ():
24
24
return '' .join (random .choice (string .ascii_lowercase ) for i in range (20 ))
25
25
26
- class LivewireComponent ():
26
+ class LivewireComponent (object ):
27
27
id = None
28
- context = {}
29
28
30
29
def get_component_name (self ):
31
30
return self .component_name .lower ()
32
31
33
- def get_context (self , ** kwargs ):
34
- self .context .update (kwargs )
35
- return self .context
36
-
37
32
def get_dom (self ):
38
33
context = self .get_context ()
39
34
return self ._render_component (context )
@@ -55,9 +50,17 @@ def get_response(self):
55
50
'checksum' : "c24"
56
51
}
57
52
53
+ def update_context (self , data_context ):
54
+ context = self .get_context ()
55
+ context .update (data_context )
56
+ for key , value in context .items ():
57
+ setattr (self , key ,value )
58
+ return context
59
+
60
+
58
61
def parser_payload (self , payload ):
59
62
self .id = payload .get ("id" )
60
- self .context . update (payload .get ("data" ))
63
+ self .update_context (payload .get ("data" ))
61
64
action_queue = payload .get ("actionQueue" , [])
62
65
for action in action_queue :
63
66
action_type = action .get ("type" )
@@ -66,7 +69,10 @@ def parser_payload(self, payload):
66
69
method = payload .get ("method" )
67
70
params = payload .get ("params" ,[])
68
71
"""
69
- RUN THIS IT IS REALLY SAFE ???
72
+ TODO:
73
+ RUN THIS IT IS REALLY SAFE ???
74
+ https://www.toptal.com/python/python-design-patterns
75
+ patterns
70
76
"""
71
77
local_method = getattr (self , method )
72
78
local_method (* params )
@@ -94,12 +100,12 @@ def render_initial(self):
94
100
initial_data = {
95
101
'id' : self .id ,
96
102
'name' : component ,
97
- 'redirectTo' :"" ,
103
+ 'redirectTo' : False ,
98
104
"events" : [],
99
105
"eventQueue" : [],
100
106
"dispatchQueue" : [],
101
107
"data" : context ,
102
- "children" : [] ,
108
+ "children" : {} ,
103
109
"checksum" : "9e4c194bb6aabf5f1" # TODO: checksum
104
110
}
105
111
return self ._render_component (context , initial_data = initial_data )
0 commit comments