0.0.263 • Published 10 months ago

@elf-framework/sapa v0.0.263

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@elf-framework/sapa

Fantastic UI library

Install

npm install @elf-framework/sapa 

// or 

yarn add @elf-framework/sapa 

ready to use JSX

vite config

esbuild: {
    jsxFactory: "createElementJsx",
    jsxFragment: "FragmentInstance",
    jsxInject: `import { createElementJsx, FragmentInstance } from "@elf-framework/sapa"`,
},

use jsx-runtime

tsconfig.json

"compilerOptions": {
  "jsx": "react-jsx",
  "jsxImportSource": "@elf-framework/sapa",
}

Core Concept

Sapa is a library for easily creating DOM-based UIs. However, since it uses JSX as a grammar, it can be used as data.

The basic template uses JSX, and many functions are structured similarly to React, providing a structure that anyone who has used React can move comfortably.

JSX

It uses JSX as the template engine.

function MyApp() {
  return <div>Sample Text</div>
}

 

JSX basically exists in a form similar to html. For example, instead of using the class attribute as className , apply it as class .

function MyApp() {
  return <div class="layout">SampleText</div>
}

 

You can also use the className attribute as is. If you use the className attribute, it is automatically linked to the class attribute.

Component

Sapa consists of two components.

  • Class component
  • Function component

Class Component

import {UIElement} from "@elf-framework/sapa";

class MyApp extends UIElement {
  template () {
    return <div>My App</div>
  }
}

Function Component

function MyApp() {
  return <div>My App</div>
}

Hook

You can use a Hook similar to React.

  • useState
  • useCallback
  • useMemo
  • useReducer
  • useContext
  • useRef
  • useEffect

See here for details.

DOM

It has several features that allow you to directly control the DOM.

  • ref - Provides a selector to directly access the dom node.
  • event - Provides a magic method to easily set the dom event.

DOM Event

You can set various DOM events using Magic Methods.

import {CLICK, ALT} from "@elf-framework/sapa";

class MyApp extends UIElement {
  template() {
    return <div>My App</div>
  }

  [CLICK() + ALT] (e) {
    console.log(e);
  }
}

Store

Sapa basically provides 3 types of store.

  • state : Rendering control through the instance state and setState function used inside the component
  • useState: Sorted storage used inside the component, rendering control with update function
  • $store : Message passing through subscribe, a public repository used in component inheritance

The above three types allow us to handle data in various ways.

instance state

class MyApp extends UIElement {
  template () {
    return <div>{this.state.myVariable}</div>
  }

  [CLICK()] () {
    const { myVariable = 0 } = this.state;
    myVariable++;
    this.setState({ myVariable })
  }
}

hook state

function MyApp () {
  const [myVariable, setMyVariable] = useState(0);

  return <div onClick={() => setMyVariable(myVariable+1)}>{myVariable}</div>
}

hierarchy store

import {useStoreValue} from "@elf-framework/sapa";

class MyApp extends UIElement {
  template () {

    // subscribe event for $store
    const [myVariable, setMyVariable] = useStoreValue("myVariable", 0);

    return <div onClick={() => {
      setMyVariable((v) => v + 1);
    }}>{myVariable}</div>
  }
}

Message

Sapa provides a way to send messages from an internal component hierarchy.

import {useComponentRender} from "@elf-framework/sapa";

function MyApp () {

  useComponentRender("refreshComponent");

  return <div onClick={() => {
    this.emit("refreshComponent");
  }}></div>
}

Sapa focuses on how to store data, how to send messages, and how to render DOM through JSX.

start, hydrate, renderToHtml

Hot Module Reloader

License : MIT

0.0.263

10 months ago

0.0.262

10 months ago

0.0.249

1 year ago

0.0.247

1 year ago

0.0.246

1 year ago

0.0.244

1 year ago

0.0.242

1 year ago

0.0.252

12 months ago

0.0.250

12 months ago

0.0.159

1 year ago

0.0.158

1 year ago

0.0.153

1 year ago

0.0.150

1 year ago

0.0.157

1 year ago

0.0.156

1 year ago

0.0.155

1 year ago

0.0.154

1 year ago

0.0.205

1 year ago

0.0.204

1 year ago

0.0.202

1 year ago

0.0.209

1 year ago

0.0.208

1 year ago

0.0.206

1 year ago

0.0.164

1 year ago

0.0.163

1 year ago

0.0.162

1 year ago

0.0.161

1 year ago

0.0.201

1 year ago

0.0.200

1 year ago

0.0.167

1 year ago

0.0.166

1 year ago

0.0.165

1 year ago

0.0.160

1 year ago

0.0.216

1 year ago

0.0.215

1 year ago

0.0.214

1 year ago

0.0.213

1 year ago

0.0.218

1 year ago

0.0.217

1 year ago

0.0.174

1 year ago

0.0.212

1 year ago

0.0.179

1 year ago

0.0.211

1 year ago

0.0.178

1 year ago

0.0.210

1 year ago

0.0.177

1 year ago

0.0.176

1 year ago

0.0.171

1 year ago

0.0.170

1 year ago

0.0.227

1 year ago

0.0.226

1 year ago

0.0.225

1 year ago

0.0.224

1 year ago

0.0.229

1 year ago

0.0.228

1 year ago

0.0.107

1 year ago

0.0.184

1 year ago

0.0.223

1 year ago

0.0.222

1 year ago

0.0.189

1 year ago

0.0.221

1 year ago

0.0.220

1 year ago

0.0.180

1 year ago

0.0.117

1 year ago

0.0.119

1 year ago

0.0.239

1 year ago

0.0.118

1 year ago

0.0.197

1 year ago

0.0.195

1 year ago

0.0.194

1 year ago

0.0.231

1 year ago

0.0.193

1 year ago

0.0.192

1 year ago

0.0.191

1 year ago

0.0.190

1 year ago

0.0.125

1 year ago

0.0.129

1 year ago

0.0.241

1 year ago

0.0.120

1 year ago

0.0.124

1 year ago

0.0.123

1 year ago

0.0.139

1 year ago

0.0.138

1 year ago

0.0.130

1 year ago

0.0.149

1 year ago

0.0.141

1 year ago

0.0.145

1 year ago

0.0.144

1 year ago

0.0.143

1 year ago

0.0.85

2 years ago

0.0.41

2 years ago

0.0.80

2 years ago

0.0.82

2 years ago

2.2.0

2 years ago

2.1.47

2 years ago

2.2.2

2 years ago

2.1.45

2 years ago

2.2.4

2 years ago

2.2.7

2 years ago

2.1.43

2 years ago

2.2.6

2 years ago

0.0.37

2 years ago

0.0.74

2 years ago

0.0.30

2 years ago

0.0.75

2 years ago

0.0.32

2 years ago

0.0.71

2 years ago

0.0.72

2 years ago

0.0.26

2 years ago

0.0.29

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.61

2 years ago

2.1.25

2 years ago

0.0.15

2 years ago

0.0.17

2 years ago

0.0.51

2 years ago

0.0.10

2 years ago

0.0.12

2 years ago

2.2.8

2 years ago

0.0.3

2 years ago

2.1.36

2 years ago

2.1.35

2 years ago

2.1.33

2 years ago

0.0.9

2 years ago

0.0.4

2 years ago

2.1.23

2 years ago

2.1.19

2 years ago

2.1.15

2 years ago

2.1.9

2 years ago

2.1.8

2 years ago

2.1.7

2 years ago

2.1.6

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.2

2 years ago

2.1.0

2 years ago

2.0.49

2 years ago

2.0.47

2 years ago

2.0.46

2 years ago

2.0.43

2 years ago

2.0.42

2 years ago

2.0.41

2 years ago

2.0.39

2 years ago

2.0.37

2 years ago

2.0.34

2 years ago

2.0.32

2 years ago

2.0.29

2 years ago

2.0.28

2 years ago

2.0.24

2 years ago

2.0.20

2 years ago

2.0.16

2 years ago

2.0.12

2 years ago

2.0.10

2 years ago

2.0.8

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

1.1.1

2 years ago

1.0.0

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago