Skip to content

Commit

Permalink
implemented delete method
Browse files Browse the repository at this point in the history
  • Loading branch information
Oudwins committed Dec 10, 2023
1 parent 768b891 commit 113604b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ ds.selector("css selector"); // .class, #id....

**Action methods**

Get: Returns a css in js object for the nodes selected;

```js
ds.selector("div").get(); // {div: {background: "red"}}
```

Set: sets the node to the provided value
The set function may be used to set nodes but this is not recomended as it may lead to unsupported behaviours -> ds.set({"div": {background: "red"}})

Expand All @@ -89,10 +95,11 @@ ds.selector("div").set({ background: "blue", color: "white" }); // css is not up
ds.media("(max-width: 300px)").set({ div: { background: "red" } }); // NOT RECOMENDED
```

Get: Returns a css in js object for the nodes selected;
Delete: delete a node and its child nodes

```js
ds.selector("div").get(); // {div: {background: "red"}}
ds.selector("div").delete(); // deletes div{background: "red"}
ds.media("(max-width: 300px)").delete(); //deletes media query & all nodes inside it!
```

### Storing and Recovering the css
Expand Down
5 changes: 5 additions & 0 deletions src/createDynamicStylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export function createDynamicStyleSheetHandlerFactory(
return postcss.objectify(n);
reset();
},
delete() {
const diff = astInterface.removeNode(qpath, ast);
ss.processDiffs(diff);
reset();
},
_ast: ast,
_ssInterface: ss,
};
Expand Down

0 comments on commit 113604b

Please sign in to comment.