@iankibetsh/vue-streamline 1.1.9 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -32,11 +32,19 @@ Vue.use(streamline, {
32
32
  import { useStreamline } from '@iankibet/vue-streamline'
33
33
 
34
34
 
35
- const {getActionUrl, service:tasksService} = useStreamline('tasks')
35
+ const {getActionUrl, service:tasksService, props} = useStreamline('tasks')
36
36
 
37
- // call the service methods
37
+ ```
38
+
39
+ ## Calling an action/method in the service
40
+
41
+ You can call an action/method in the service by calling the method on the service object
42
+ ```js
43
+ const res = await tasksService.getTasks()
44
+
45
+ // or
38
46
 
39
- tasksServices.getTasks().then(response => {
47
+ tasksService.getTasks().then(response => {
40
48
  console.log(response)
41
49
  })
42
50
  ```
@@ -47,4 +55,14 @@ tasksServices.getTasks().then(response => {
47
55
  You can get the url to an action/method in the service by calling the getActionUrl method on the service object passing the action name and any parameters
48
56
  ```js
49
57
  getActionUrl('getTasks', 'active')
50
- ```
58
+ ```
59
+
60
+ ## Accessing class properties
61
+ In your template just access the props object to get the class properties
62
+ ```html
63
+ <template>
64
+ <div>
65
+ <h1>{{props.title}}</h1>
66
+ </div>
67
+ </template>
68
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iankibetsh/vue-streamline",
3
- "version": "1.1.9",
3
+ "version": "1.2.2",
4
4
  "description": "Vue library for streamlining laravel backend services with @iankibet/streamline composer package",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/App.vue CHANGED
@@ -2,7 +2,7 @@
2
2
  import useStreamline from './composables/useStreamline.js'
3
3
  import { onMounted, ref, toRefs } from 'vue'
4
4
 
5
- const {loading, service:paybillService, getActionUrl} = useStreamline('mpesa/paybill',32)
5
+ const {loading, service:paybillService, getActionUrl,props} = useStreamline('mpesa/paybill')
6
6
 
7
7
 
8
8
  const foundPaybill = ref(null)
@@ -21,8 +21,12 @@ const findPaybill = async ()=>{
21
21
  <template>
22
22
  <div>
23
23
  <hr/>
24
+ <h3>Destructed: {{ testKey }}</h3>
25
+ <h3>Original: {{ props.testKey }}</h3>
26
+ <h3>Original: {{ props.testKey }}</h3>
27
+ <h3>Original: {{ props.testKey }}</h3>
28
+ <h3>Original: {{ props.testKey }}</h3>
24
29
  <h3 class="text-success" >Loading : {{ loading }}</h3>
25
- <h5>Found Paybill : {{ paybillService.paybill }}</h5>
26
30
  <h1 @click="findPaybill">Get Paybill</h1>
27
31
  {{ foundPaybill }}
28
32
  </div>
@@ -14,6 +14,20 @@ const useStreamline = (stream, ...initialArgs) => {
14
14
  const streamlineHeaders = inject('streamlineHeaders');
15
15
  const enableCache = inject('enableCache');
16
16
 
17
+ const originalProps = reactive({});
18
+
19
+ // Proxy to intercept access
20
+ const props = new Proxy(originalProps, {
21
+ get(target, property, receiver) {
22
+ if(!propertiesFetched.value) {
23
+ fetchServiceProperties().then(() => target[property]);
24
+ }
25
+ return Reflect.get(target, property, receiver); // Return the actual value
26
+ },
27
+ set(target, property, value, receiver) {
28
+ return Reflect.set(target, property, value, receiver); // Update the value
29
+ }
30
+ })
17
31
  const axios = Axios.create({
18
32
  headers: {
19
33
  ...streamlineHeaders,
@@ -31,7 +45,7 @@ const useStreamline = (stream, ...initialArgs) => {
31
45
  stream,
32
46
  params: initialArgs,
33
47
  });
34
- assignPropertiesAndMethods(response.data);
48
+ assignProperties(response.data);
35
49
  enableCache && localStorage.setItem(cacheKey, JSON.stringify(response.data));
36
50
  } catch (error) {
37
51
  console.error(`Error fetching properties for stream ${stream}`, error);
@@ -43,28 +57,9 @@ const useStreamline = (stream, ...initialArgs) => {
43
57
  }
44
58
  };
45
59
 
46
- const assignPropertiesAndMethods = (data) => {
60
+ const assignProperties = (data) => {
47
61
  Object.assign(service, data.properties); // Assign the properties to the reactive service object
48
- for (const method of data.methods) {
49
- const fn = async (...args) => {
50
- loading.value = true;
51
- try {
52
- const response = await axios.post(streamlineUrl, {
53
- action: method,
54
- stream,
55
- ...formData,
56
- params: args,
57
- });
58
- return response.data;
59
- } catch (error) {
60
- console.error(`Error calling ${method} on stream ${stream}`, error);
61
- throw error;
62
- } finally {
63
- loading.value = false;
64
- }
65
- };
66
- service[method] = fn;
67
- }
62
+ Object.assign(originalProps, data.properties); // Assign the properties to the reactive service object
68
63
  };
69
64
 
70
65
  const handler = {
@@ -117,7 +112,7 @@ const useStreamline = (stream, ...initialArgs) => {
117
112
  if (!enableCache) return;
118
113
  const cachedData = localStorage.getItem(cacheKey);
119
114
  if (cachedData) {
120
- assignPropertiesAndMethods(JSON.parse(cachedData));
115
+ assignProperties(JSON.parse(cachedData));
121
116
  }
122
117
  if (initialArgs.length > 0) {
123
118
  fetchServiceProperties();
@@ -129,6 +124,7 @@ const useStreamline = (stream, ...initialArgs) => {
129
124
  loading,
130
125
  service: new Proxy(service, handler),
131
126
  getActionUrl,
127
+ props
132
128
  };
133
129
  };
134
130
 
package/src/main.js CHANGED
@@ -11,7 +11,7 @@ const app = createApp(App)
11
11
  app.use(streamline,{
12
12
  streamlineHeaders,
13
13
  streamlineUrl,
14
- enableCache: true
14
+ enableCache: false
15
15
  })
16
16
 
17
17
  app.mount('#app')