You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An unified Javascript framework for building a highperformance web application.
2
+
A Javascript [framework](https://en.wikipedia.org/wiki/Software_framework) for building a high-performance web application.
3
3
4
4
## Motivation
5
-
Onejs provides an abstract layer over a javascript library. It enables developer/organization to write a vanilla javascript code and bind it with framework you choose to build your application with.
5
+
Onejs provides an abstract layer over a javascript library. It enables developer/organization to write a vanilla javascript code and bind it with the framework you choose to build your application with.
6
6
7
7
##### It's hard to switch between frameworks if your performance budget does not meet with one
8
-
Considering all top javascript library adds considerable amount of initial javascript chunk into your application bundle i.e. react size is ~30kb. For any larger application, switch from one framework to another is relatively complex task and requires a lot of effort and time. onejs try to solve this problem and reduce the time and effort require in switching frameworks.
8
+
Considering all top javascript library adds a considerable amount of initial javascript chunk into your application bundle i.e. react size is ~30kb. For any larger application, switching from one framework to another is a relatively complex task and requires a lot of effort and time. onejs try to solve this problem and reduce the time and effort require in switching frameworks.
9
9
10
-
##### Classical component go polluted over the time and becomes hard to maintain
11
-
This has been a common problem that after certain time your class component gets complex and a lot of business login being written into a single javascript file. With function programming approach we are trying to solve some of these problems. Developer needs to create small functions and attach those to your component. This allows you to maximize the usage of vanilla javascript.
10
+
##### Classical component go polluted over time and becomes hard to maintain
11
+
This has been a common problem that after certain amount of time your class component gets complex and a lot of business logic being written into a single javascript file. With the functional programming approach, we are trying to solve some of these problems. A developer needs to create small functions and attach those to your component. This allows you to maximize the usage of vanilla javascript.
12
12
13
13
## Installation
14
14
```
15
15
npm i -S @js-factory/onejs
16
16
```
17
17
18
18
## APIs
19
-
Onejs offers following apis.
19
+
Onejs offers the following APIs.
20
20
21
21
- Component
22
22
- withStore
23
23
- createStore
24
24
- actionCreator
25
-
- injectStore
26
25
27
-
### Component
28
-
**Component** is a higherlevel component. It creates react or preact component and binds all given properties and methods to it.
26
+
### Component
27
+
**Component** is a higher-level component. It creates a react or preact component and binds all given properties and methods to it.
29
28
30
-
Please read [hoc](https://www.npmjs.com/package/@js-factory/hoc/v/0.2.2) documentation for further details.
29
+
Please read [hoc](https://www.npmjs.com/package/@js-factory/hoc) documentation for further details.
31
30
32
31
A typical component declaration looks like this.
33
32
@@ -41,47 +40,44 @@ import someOtherHandler from './util/someOtherHandler';
41
40
importFooTmplfrom'./FooTmpl';
42
41
43
42
@Component({
44
-
componentDidMount,
45
-
someOtherHandler,
46
-
onClickHandler,
47
-
state: {
48
-
x:0
49
-
},
50
-
instanceProps: {
51
-
y:0
52
-
},
53
-
template: FooTmpl
43
+
componentDidMount,
44
+
someOtherHandler,
45
+
onClickHandler,
46
+
state: {
47
+
x:0
48
+
},
49
+
instanceProps: {
50
+
y:0
51
+
},
52
+
template: FooTmpl
54
53
})
55
54
exportdefaultclassFooComponent { }
56
55
57
56
```
58
57
59
-
### withStore
60
-
Every frontend application needs a data store. `withStore` provide a simple data store and wire a newly created `Component` with application store. Your typical store will be a plain javascript object.
58
+
### withStore
59
+
Every frontend application (read SPA) needs a persistent data store. The application should be able to maintain its state during back & forth page transitions. `withStore` connects the component with application's data store.
61
60
62
-
```js
61
+
Configuring `withStore` is very simple. It has two options. 1) **watcher** , 2) action
62
+
63
+
#### watcher
64
+
Data store of an application is a big JavaScript objects. It holds the application state. **watcher** represents the keys in applications store (read a big javascript object). When you define watcher in `withStore`, onejs connects your component with the application store and any changes to these properties will update (re-render) the component.
63
65
66
+
// App data store
67
+
68
+
```js
64
69
constappDataStore= {
65
-
key1: {
66
-
// some data
67
-
},
68
-
key2: {
69
-
// some data
70
-
},
71
-
key3: {
72
-
// some data
73
-
}
70
+
todos: [
71
+
// todo
72
+
],
73
+
counter:0// initial value
74
74
};
75
-
76
75
```
77
76
78
-
`withStore` configuration is very simple and has two options.
79
-
80
-
#### watcher
81
-
**watcher** is nothing but keys in application store. When you define watcher with `withStore`, onejs connects your component with application store and any changes to these properties will trigger a re-render.
82
-
83
77
#### action
84
-
Action allows you to update store.
78
+
The only way to connect to the store is an `action`. Actions allow you to modify the application state.
79
+
80
+
**Complete Example**
85
81
86
82
```javascript
87
83
@@ -94,59 +90,58 @@ import onClickHandler from './handlers/onClickHandler';
**createStore** initializes application store. It takes 2 arguments to build the store. 1) initial state of an application, and 2) middlewares to execute before updating the store properties.
136
+
**createStore** initializes application store. It takes 2 arguments to build the store. 1) initial state of an application, and 2) middleware(s) to execute before updating the store properties.
0 commit comments